ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-12-29 10:30:12
Exec Total Coverage
Lines: 3113 8805 35.4%
Functions: 84 312 26.9%
Branches: 2715 7963 34.1%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "gui/jwin.h"
15 #include "metadata/metadata.h"
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/packfile.h"
20 #include "base/cpool.h"
21 #include "base/autocombo.h"
22 #include "base/gui.h"
23 #include "base/msgstr.h"
24 #include "zc/zelda.h"
25 #include "zq/zq_class.h"
26 #include "zq/render.h"
27 #include "zq/render_map_view.h"
28 #include "zq/zq_misc.h"
29 #include "zq/zquest.h"
30 #include "base/qst.h"
31 #include "base/colors.h"
32 #include "tiles.h"
33 #include "base/zsys.h"
34 #include "sprite.h"
35 #include "items.h"
36 #include "zc/zc_sys.h"
37 #include "base/md5.h"
38 #include "hero_tiles.h"
39 #include "subscr.h"
40 #include "zq/zq_strings.h"
41 #include "zq/zq_subscr.h"
42 #include "zc/ffscript.h"
43 #include "base/util.h"
44 #include "zq/zq_files.h"
45 #include "slopes.h"
46 #include "drawing.h"
47 #include "zinfo.h"
48 #include "zq/render_minimap.h"
49 #include "base/mapscr.h"
50 #include "iter.h"
51 #include <fmt/format.h>
52 #include <filesystem>
53
54 #ifdef __EMSCRIPTEN__
55 #include "base/emscripten_utils.h"
56 #endif
57
58 namespace fs = std::filesystem;
59
60 using namespace util;
61
62 extern uint8_t ViewLayer3BG, ViewLayer2BG;
63 extern int32_t LayerDitherBG, LayerDitherSz;
64 extern bool NoHighlightLayer0;
65
66 using std::string;
67 using std::pair;
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 12 zmap Map;
80 int32_t prv_mode=0;
81
82 bool save_warn=true;
83
84 int32_t COMBOPOS(int32_t x, int32_t y)
85 {
86 return (((y) & 0xF0) + ((x) >> 4));
87 }
88 int32_t COMBOPOS_B(int32_t x, int32_t y)
89 {
90 if(unsigned(x) >= 256 || unsigned(y) >= 176)
91 return -1;
92 return COMBOPOS(x,y);
93 }
94 int32_t COMBOX(int32_t pos)
95 {
96 return ((pos) % 16 * 16);
97 }
98 int32_t COMBOY(int32_t pos)
99 {
100 return ((pos) & 0xF0);
101 }
102
103 void reset_dmap(int32_t index)
104 {
105 bound(index,0,MAXDMAPS-1);
106 DMaps[index].clear();
107 DMaps[index].title = "";
108 sprintf(DMaps[index].intro, " ");
109 }
110
111 void reset_dmaps()
112 {
113 for(int32_t i=0; i<MAXDMAPS; i++)
114 reset_dmap(i);
115 }
116
117 void truncate_dmap_title(std::string& title)
118 {
119 title.resize(21, ' ');
120 }
121
122 mapscr* zmap::get_prvscr()
123 {
124 return &prvscr;
125 }
126
127
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
128 {
129 23 can_paste=false;
130 23 prv_cmbcycle=0;
131 23 prv_advance=0;
132 23 prv_freeze=0;
133 23 copyffc=-1;
134
135 23 memset(scrpos, 0, sizeof(scrpos));
136 23 memset(scrview, 0, sizeof(scrview));
137 23 screens=NULL;
138 23 prv_time=0;
139 23 prv_scr=0;
140 23 prv_map=0;
141 23 copyscr=0;
142 23 cursor={};
143 copymap=0;
144 layer_target_map = 0;
145 layer_target_scr = 0;
146 layer_target_multiple = 0;
147 }
148
149 11 void zmap::clear()
150 {
151
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
152 11 }
153 void zmap::force_refr_pointer()
154 {
155 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
156 screens = nullptr;
157 else screens = &TheMaps[cursor.map*MAPSCRS];
158 }
159 bool zmap::CanUndo()
160 {
161 return input_undo_stack.size() > 0;
162 }
163 bool zmap::CanRedo()
164 {
165 return input_redo_stack.size() > 0;
166 }
167 bool zmap::CanPaste()
168 {
169 return can_paste;
170 }
171 int32_t zmap::CopyScr()
172 {
173 return (copymap<<8)+copyscr;
174 }
175 int32_t zmap::getCopyFFC()
176 {
177 return copyffc;
178 }
179 set_ffc_command::data_t zmap::getCopyFFCData()
180 {
181 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
182 }
183 67 int32_t zmap::getMapCount()
184 {
185 67 return map_count;
186 }
187 int32_t zmap::getLayerTargetMap()
188 {
189 return layer_target_map;
190 }
191 int32_t zmap::getLayerTargetScr()
192 {
193 return layer_target_scr;
194 }
195 int32_t zmap::getLayerTargetMultiple()
196 {
197 return layer_target_multiple;
198 }
199 bool zmap::isDungeon(int32_t scr)
200 {
201 for(int32_t i=0; i<4; i++)
202 {
203 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
204 {
205 return false;
206 }
207 }
208
209 return true;
210 }
211
212 bool zmap::clearall(bool validate)
213 {
214 Color=0;
215 char tbuf[10];
216
217 if((header.templatepath[0]!=0)&&validate)
218 {
219 if(!valid_zqt(header.templatepath))
220 {
221 displayinfo("Error","Invalid Quest Template");
222 return false;
223 }
224 }
225
226 for(int32_t i=0; i<map_count; i++)
227 {
228 setCurrMap(i);
229 sprintf(tbuf, "%d", i);
230 clearmap(true);
231 }
232
233 setCurrMap(0);
234 return true;
235 }
236
237 bool zmap::reset_templates(bool validate)
238 {
239 //why are we doing this?
240 if(colordata==NULL)
241 {
242 return false;
243 }
244
245 //int32_t ret;
246 word version, build, dummy, sversion=0;
247 byte dummyc;
248 word dummyw;
249 //int32_t section_size;
250 word temp_map_count;
251 mapscr temp_mapscr;
252 PACKFILE *f=NULL;
253
254 // setPackfilePassword(datapwd);
255 f=open_quest_template(&header, "modules/classic/default.qst", validate);
256 get_version_and_build(f, &version, &build);
257
258 if(!find_section(f, ID_MAPS))
259 {
260 // setPackfilePassword(NULL);
261 return false;
262 }
263
264 //section version info
265 if(!p_igetw(&sversion,f))
266 {
267 return false;
268 }
269
270 if(!p_igetw(&dummy,f))
271 {
272 return false;
273 }
274
275 //section size
276 dword dummy_size;
277 if(!p_igetl(&dummy_size,f))
278 {
279 return false;
280 }
281
282 //finally... section data
283 if(!p_igetw(&temp_map_count,f))
284 {
285 return false;
286 }
287
288 if(version>12)
289 {
290 if(!p_getc(&dummyc,f))
291 return qe_invalid;
292
293 if(!p_getc(&dummyc,f))
294 return qe_invalid;
295
296 if(!p_igetw(&dummyw,f))
297 return qe_invalid;
298
299 if(!p_igetw(&dummyw,f))
300 return qe_invalid;
301
302 if(!p_igetw(&dummyw,f))
303 return qe_invalid;
304
305 if(!p_igetw(&dummyw,f))
306 return qe_invalid;
307
308 if(!p_igetw(&dummyw,f))
309 return qe_invalid;
310
311 if(!p_igetw(&dummyw,f))
312 return qe_invalid;
313
314 if(!p_igetw(&dummyw,f))
315 return qe_invalid;
316
317 if(!p_igetw(&dummyw,f))
318 return qe_invalid;
319
320 if(!p_igetw(&dummyw,f))
321 return qe_invalid;
322
323 if(!p_igetw(&dummyw,f))
324 return qe_invalid;
325
326 if(!p_getc(&dummyc,f))
327 return qe_invalid;
328
329 if(!p_getc(&dummyc,f))
330 return qe_invalid;
331 }
332
333 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
334 {
335 readmapscreen(f, &header, &temp_mapscr, sversion);
336 }
337
338 readmapscreen(f, &header, &TheMaps[128], sversion);
339 readmapscreen(f, &header, &TheMaps[129], sversion);
340
341 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
342 {
343 readmapscreen(f, &header, &temp_mapscr, sversion);
344 }
345
346 if(version>12)
347 {
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353
354 if(!p_igetw(&dummyw,f))
355 return qe_invalid;
356
357 if(!p_igetw(&dummyw,f))
358 return qe_invalid;
359
360 if(!p_igetw(&dummyw,f))
361 return qe_invalid;
362
363 if(!p_igetw(&dummyw,f))
364 return qe_invalid;
365
366 if(!p_igetw(&dummyw,f))
367 return qe_invalid;
368
369 if(!p_igetw(&dummyw,f))
370 return qe_invalid;
371
372 if(!p_igetw(&dummyw,f))
373 return qe_invalid;
374
375 if(!p_igetw(&dummyw,f))
376 return qe_invalid;
377
378 if(!p_igetw(&dummyw,f))
379 return qe_invalid;
380
381 if(!p_igetw(&dummyw,f))
382 return qe_invalid;
383
384 if(!p_getc(&dummyc,f))
385 return qe_invalid;
386
387 if(!p_getc(&dummyc,f))
388 return qe_invalid;
389 }
390
391 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
392 {
393 readmapscreen(f, &header, &temp_mapscr, sversion);
394 }
395
396 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
398
399 pack_fclose(f);
400 clear_quest_tmpfile();
401
402 return true;
403 }
404
405 bool zmap::clearmap(bool newquest)
406 {
407 if(cursor.map<map_count)
408 {
409 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
410 {
411 clearscr(i);
412 }
413
414 setCurrScr(0);
415
416 if(newquest)
417 {
418 if(!reset_templates(false))
419 {
420 displayinfo("Error","Error resetting template screens.");
421 }
422 }
423 }
424
425 return true;
426 }
427
428 MapCursor zmap::getCursor() const
429 {
430 return cursor;
431 }
432
433 11 void zmap::setCursor(MapCursor new_cursor)
434 {
435
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
436 return;
437
438
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
439 pushCursorToHistory(std::move(cursor));
440 11 cursor = std::move(new_cursor);
441
442
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
443 11 screens = &TheMaps[cursor.map*MAPSCRS];
444
445 11 refresh_color();
446 11 setlayertarget();
447 11 reset_combo_animations2();
448 11 mmap_mark_dirty();
449 11 regions_mark_dirty();
450 11 }
451
452 void zmap::pushCursorToHistory(MapCursor cursor)
453 {
454 if (cursor_history_enabled)
455 {
456 cursor_undo_stack.push_back(std::move(cursor));
457 cursor_redo_stack = {};
458 CapCursorHistory();
459 }
460 }
461
462 bool zmap::isValidPosition(ComboPosition pos) const
463 {
464 return pos.is_valid(cursor);
465 }
466
467 int zmap::getScreenForPosition(ComboPosition pos) const
468 {
469 return cursor.viewscr + pos.screen_offset();
470 }
471
472 mapscr* zmap::CurrScr()
473 {
474 return screens+cursor.screen;
475 }
476 mapscr* zmap::Scr(int32_t scr)
477 {
478 return screens+scr;
479 }
480 mapscr* zmap::Scr(ComboPosition pos)
481 {
482 if (!pos.is_valid(cursor))
483 return nullptr;
484
485 int screen_offset = pos.screen_offset();
486 int screen = cursor.viewscr + screen_offset;
487 return AbsoluteScr(cursor.map, screen);
488 }
489 mapscr* zmap::Scr(ComboPosition pos, int layer)
490 {
491 int map = cursor.map;
492 int screen = cursor.viewscr + pos.screen_offset();
493 if (layer)
494 {
495 mapscr* scr = Map.AbsoluteScr(map, screen);
496 map = scr->layermap[CurrentLayer-1]-1;
497 screen = scr->layerscreen[CurrentLayer-1];
498 }
499
500 return AbsoluteScr(map, screen);
501 }
502 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
503 {
504 mapscr* scr = Scr(pos, layer);
505 if (scr && !(scr->valid&mVALID))
506 {
507 scr->valid |= mVALID;
508 setcolor(Color, scr);
509 }
510 return scr;
511 }
512 mapscr* zmap::AbsoluteScr(int32_t scr)
513 {
514 if(unsigned(scr) >= MAPSCRS*getMapCount())
515 return nullptr;
516 return &TheMaps[scr];
517 }
518 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
519 {
520 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
521 return nullptr;
522 return AbsoluteScr((map*MAPSCRS)+scr);
523 }
524 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
525 {
526 mapscr* scr = AbsoluteScr(map, screen);
527 if (scr && !(scr->valid&mVALID))
528 {
529 scr->valid |= mVALID;
530 setcolor(Color, scr);
531 }
532 return scr;
533 }
534 void zmap::set_prvscr(int32_t map, int32_t scr)
535 {
536 prvscr = *get_canonical_scr(map, scr);
537
538 for(int32_t i=0; i<6; i++)
539 {
540 if(prvscr.layermap[i]>0)
541 {
542 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
543 }
544 else
545 prvlayers[i].valid = 0;
546 }
547
548 prv_map=map;
549 prv_scr=scr;
550 }
551 92 int32_t zmap::getCurrMap()
552 {
553 92 return cursor.map;
554 }
555 11 void zmap::regions_mark_dirty()
556 {
557 11 regions_dirty = true;
558 11 }
559 void zmap::regions_refresh()
560 {
561 if (!regions_dirty)
562 return;
563
564 regions_dirty = false;
565 region_descriptions.clear();
566
567 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
568 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
569 region_descriptions.clear();
570 }
571 const std::vector<region_description>& zmap::get_region_descriptions()
572 {
573 regions_refresh();
574 return region_descriptions;
575 }
576 bool zmap::is_region(int screen)
577 {
578 if (screen < 0 || screen >= 128)
579 return false;
580
581 regions_refresh();
582 return current_map_region_ids[screen];
583 }
584 bool zmap::isDark(int scr)
585 {
586 return (screens[scr].flags&fDARK)!=0;
587 }
588 bool zmap::isValid(int32_t scr)
589 {
590 return (screens[scr].valid&mVALID)!=0;
591 }
592 bool zmap::isValid(int32_t map, int32_t scr)
593 {
594 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
595 }
596
597 void zmap::setCurrMap(int32_t index)
598 {
599 scrpos[cursor.map] = cursor.screen;
600 scrview[cursor.map] = cursor.viewscr;
601
602 auto new_cursor = cursor;
603 new_cursor.map = bound(index,0,map_count);
604
605 new_cursor.viewscr = scrview[new_cursor.map];
606 new_cursor.setScreen(scrpos[new_cursor.map]);
607 setCursor(std::move(new_cursor));
608 }
609
610 20 int32_t zmap::getCurrScr()
611 {
612 20 return cursor.screen;
613 }
614 void zmap::setCurrScr(int32_t scr)
615 {
616 if (scr == cursor.screen)
617 return;
618
619 auto new_cursor = cursor;
620 new_cursor.setScreen(scr);
621 setCursor(std::move(new_cursor));
622 }
623
624 int32_t zmap::getViewScr()
625 {
626 return cursor.viewscr;
627 }
628
629 void zmap::setViewSize(int32_t size)
630 {
631 auto new_cursor = cursor;
632 new_cursor.setSize(size);
633 setCursor(std::move(new_cursor));
634 }
635
636 1 int32_t zmap::getViewSize()
637 {
638 1 return cursor.size;
639 }
640
641 11 void zmap::setlayertarget()
642 {
643 11 layer_target_map = 0;
644 11 layer_target_multiple = 0;
645
646
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
647 {
648
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
649 {
650 7616 int32_t i=(m*MAPSCRS+s);
651 7616 mapscr *ts=&TheMaps[i];
652
653 // Search through each layer
654
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
655 {
656
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
657 {
658 if(layer_target_map > 0)
659 {
660 layer_target_multiple += 1;
661 continue;
662 }
663
664 layer_target_map = m+1;
665 layer_target_scr = s;
666 }
667 45696 }
668 7616 }
669 56 }
670 11 }
671
672 11 void zmap::refresh_color()
673 {
674 11 auto color = getcolor();
675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
676 {
677 11 loadlvlpal(color);
678 11 rebuild_trans_table();
679 11 }
680 11 }
681
682 void zmap::setcolor(int color, mapscr* scr)
683 {
684 if (!scr)
685 scr = CurrScr();
686 scr->valid |= mVALID;
687 scr->color = color;
688
689 refresh_color();
690
691 mmap_mark_dirty();
692 }
693
694 11 int32_t zmap::getcolor()
695 {
696 11 return getcolor(cursor.screen);
697 }
698
699 11 int32_t zmap::getcolor(int screen)
700 {
701
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
702
703
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
704 11 return scr.color;
705
706 return map_infos[cursor.map].autopalette;
707 11 }
708
709 void zmap::resetflags()
710 {
711 byte *di=&(screens[cursor.screen].valid);
712
713 for(int32_t i=1; i<48; i++)
714 {
715 *(di+i)=0;
716 }
717 }
718
719 word zmap::tcmbdat(int32_t pos)
720 {
721 return screens[TEMPLATE].data[pos];
722 }
723
724 word zmap::tcmbcset(int32_t pos)
725 {
726 return screens[TEMPLATE].cset[pos];
727 }
728
729 int32_t zmap::tcmbflag(int32_t pos)
730 {
731 return screens[TEMPLATE].sflag[pos];
732 }
733
734 word zmap::tcmbdat2(int32_t pos)
735 {
736 return screens[TEMPLATE2].data[pos];
737 }
738
739 word zmap::tcmbcset2(int32_t pos)
740 {
741 return screens[TEMPLATE2].cset[pos];
742 }
743
744 int32_t zmap::tcmbflag2(int32_t pos)
745 {
746 return screens[TEMPLATE2].sflag[pos];
747 }
748
749 void zmap::TemplateAll()
750 {
751 StartListCommand();
752 for(int32_t i=0; i<128; i++)
753 {
754 if((screens[i].valid&mVALID) && isDungeon(i))
755 DoTemplateCommand(-1, -1, i);
756 }
757 FinishListCommand();
758 }
759
760 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
761 {
762 if(scr==TEMPLATE)
763 return;
764
765 if(!(screens[scr].valid&mVALID))
766 screens[scr].color=Color;
767
768 screens[scr].valid|=mVALID;
769
770 for(int32_t i=0; i<32; i++)
771 {
772 screens[scr].data[i]=screens[TEMPLATE].data[i];
773 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
774 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
775 }
776
777 for(int32_t i=144; i<176; i++)
778 {
779 screens[scr].data[i]=screens[TEMPLATE].data[i];
780 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
781 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
782 }
783
784 for(int32_t y=2; y<=9; y++)
785 {
786 int32_t j=y<<4;
787 screens[scr].data[j]=screens[TEMPLATE].data[j];
788 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
789 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
790 ++j;
791 screens[scr].data[j]=screens[TEMPLATE].data[j];
792 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
793 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
794 ++j;
795 j+=12;
796 screens[scr].data[j]=screens[TEMPLATE].data[j];
797 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
798 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
799 ++j;
800 screens[scr].data[j]=screens[TEMPLATE].data[j];
801 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
802
803 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
804 ++j;
805 }
806
807 if(floorcombo!=-1)
808 {
809 for(int32_t y=2; y<9; y++)
810 for(int32_t x=2; x<14; x++)
811 {
812 int32_t i=(y<<4)+x;
813 screens[scr].data[i] = floorcombo;
814 screens[scr].cset[i] = floorcset;
815 }
816 }
817
818 for(int32_t i=0; i<4; i++)
819 putdoor(scr,i,screens[scr].door[i]);
820 }
821
822
823 void zmap::clearscr(int32_t scr)
824 {
825 screens[scr].zero_memory();
826 screens[scr].valid=mVERSION;
827 auto const& mapinf = map_infos[cursor.map];
828 for(int q = 0; q < 6; ++q)
829 {
830 auto layer = mapinf.autolayers[q];
831 screens[scr].layermap[q] = layer;
832 screens[scr].layerscreen[q] = layer ? scr : 0;
833 }
834 screens[scr].color = mapinf.autopalette;
835 if (scr == cursor.screen)
836 refresh_color();
837 mmap_mark_dirty();
838 }
839
840 const char *loaderror[] =
841 {
842
843 "OK","File not found","Incomplete data",
844 "Invalid version","Invalid file"
845
846 };
847
848 int32_t zmap::load(const char *path)
849 {
850 PACKFILE *f=pack_fopen_password(path,F_READ, "");
851
852 if(!f)
853 return 1;
854
855
856 int16_t version;
857 byte build;
858
859 //get the version
860 if(!p_igetw(&version,f))
861 {
862 goto file_error;
863 }
864
865 //get the build
866 if(!p_getc(&build,f))
867 {
868 goto file_error;
869 }
870
871 for(int32_t i=0; i<MAPSCRS; i++)
872 {
873 mapscr tmpimportscr;
874 tmpimportscr.zero_memory();
875 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
876 {
877 al_trace("failed zmap::load\n");
878 goto file_error;
879 }
880
881 switch(ImportMapBias)
882 {
883 case 0:
884 *(screens+i) = tmpimportscr;
885 break;
886
887 case 1:
888 if(!(screens[i].valid&mVALID))
889 {
890 *(screens+i) = tmpimportscr;
891 }
892 break;
893
894 case 2:
895 if(tmpimportscr.valid&mVALID)
896 {
897 *(screens+i) = tmpimportscr;
898 }
899 break;
900 }
901 }
902
903
904 pack_fclose(f);
905
906 setCurrScr(0);
907 mmap_mark_dirty();
908 regions_mark_dirty();
909 return 0;
910
911 file_error:
912 pack_fclose(f);
913 clearmap(false);
914 return 2;
915 }
916
917 int32_t zmap::save(const char *path)
918 {
919 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
920
921 if(!f)
922 return 1;
923
924 if(!p_iputw(V_MAPS,f))
925 {
926 pack_fclose(f);
927 return 3;
928 }
929
930 // This was the "build number", but that's totally useless here. Keep this junk byte
931 // so as not to totally break exports between ZC versions.
932 if(!p_putc(0,f))
933 {
934 pack_fclose(f);
935 return 3;
936 }
937
938 for(int32_t i=0; i<MAPSCRS; i++)
939 {
940 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
941 {
942 pack_fclose(f);
943 return 2;
944 }
945 }
946
947 pack_fclose(f);
948 return 0;
949 }
950
951
952 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
953 {
954 // Hookshots can be blocked by solid combos on all 3 ground layers.
955 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
956
957 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
958 return true;
959 if (c->walk&(1<<i))
960 return false;
961
962 for(int32_t k=0; k<2; k++)
963 {
964 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
965
966 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
967 {
968 return false;
969 }
970 }
971
972 return true;
973 }
974
975 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
976 {
977 // Hookshots can be blocked by solid combos on all 3 ground layers.
978 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
979
980 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
981 return true;
982 if (c->walk&(1<<i))
983 return false;
984
985 for(int32_t k=0; k<2; k++)
986 {
987 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
988
989 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
990 {
991 return false;
992 }
993 }
994
995 return true;
996 }
997
998 bool zmap::isstepable(int32_t combo)
999 {
1000 // This is kind of odd but it's true to the engine (see maps.cpp)
1001 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1002 }
1003
1004 // Returns the letter of the warp combo.
1005 int32_t zmap::warpindex(int32_t combo)
1006 {
1007 switch(combobuf[combo].type)
1008 {
1009 case cCAVE:
1010 case cPIT:
1011 case cSTAIR:
1012 case cCAVE2:
1013 case cSWIMWARP:
1014 case cDIVEWARP:
1015 case cSWARPA:
1016 return 0;
1017
1018 case cCAVEB:
1019 case cPITB:
1020 case cSTAIRB:
1021 case cCAVE2B:
1022 case cSWIMWARPB:
1023 case cDIVEWARPB:
1024 case cSWARPB:
1025 return 1;
1026
1027 case cCAVEC:
1028 case cPITC:
1029 case cSTAIRC:
1030 case cCAVE2C:
1031 case cSWIMWARPC:
1032 case cDIVEWARPC:
1033 case cSWARPC:
1034 return 2;
1035
1036 case cCAVED:
1037 case cPITD:
1038 case cSTAIRD:
1039 case cCAVE2D:
1040 case cSWIMWARPD:
1041 case cDIVEWARPD:
1042 case cSWARPD:
1043 return 3;
1044
1045 case cPITR:
1046 case cSTAIRR:
1047 case cSWARPR:
1048 return 4;
1049 }
1050
1051 return -1;
1052
1053 }
1054
1055 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1056 {
1057 if(top)
1058 line(dest,x,y,x+15,y,c);
1059 rectfill(dest,x,y,x+3,y+15,c);
1060 rectfill(dest,x+12,y,x+15,y+15,c);
1061 rectfill(dest,x+4,y+2,x+11,y+5,c);
1062 rectfill(dest,x+4,y+10,x+11,y+13,c);
1063 }
1064
1065 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1066 {
1067 line(dest,x,y,x+15,y,c);
1068 }
1069
1070 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1071 {
1072 int32_t cx = COMBOX(pos);
1073 int32_t cy = COMBOY(pos);
1074
1075 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1076
1077 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1078
1079 int32_t bridgedetected = 0;
1080
1081 for(int32_t i=0; i<4; i++)
1082 {
1083 int32_t tx=((i&2)<<2)+x;
1084 int32_t ty=((i&1)<<3)+y;
1085 int32_t tx2=((i&2)<<2)+cx;
1086 int32_t ty2=((i&1)<<3)+cy;
1087 for (int32_t m = layer; m <= 1; m++)
1088 {
1089 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1090 {
1091 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1092 {
1093 bridgedetected |= (1<<i);
1094 }
1095 }
1096 else
1097 {
1098 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1099 {
1100 bridgedetected |= (1<<i);
1101 }
1102 }
1103 }
1104 if (bridgedetected & (1<<i))
1105 {
1106 if (i >= 3) break;
1107 else continue;
1108 }
1109 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1110 {
1111 for(int32_t k=0; k<8; k+=2)
1112 for(int32_t j=0; j<8; j+=2)
1113 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1114 }
1115 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1116 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1117
1118 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1119 {
1120 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1121 {
1122 for(int32_t k=0; k<8; k+=2)
1123 for(int32_t j=0; j<8; j+=2)
1124 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1125 }
1126 else
1127 {
1128 int32_t color = COLOR_SOLID;
1129
1130 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1131 color=vc(6);
1132 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1133 color=vc(7);
1134
1135 rectfill(dest,tx,ty,tx+7,ty+7,color);
1136 }
1137 }
1138 }
1139
1140 bridgedetected = 0;
1141 for(int32_t i=0; i<4; i++)
1142 {
1143 int32_t tx2=((i&2)<<2)+cx;
1144 int32_t ty2=((i&1)<<3)+cy;
1145 for (int32_t m = 0; m <= 1; m++)
1146 {
1147 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1148 {
1149 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1150 {
1151 bridgedetected |= (1<<i);
1152 }
1153 }
1154 else
1155 {
1156 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1157 {
1158 bridgedetected |= (1<<i);
1159 }
1160 }
1161 }
1162 }
1163
1164 // Draw damage combos
1165 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1166 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1167 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1168 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1169 || combo_class_buf[c1.type].modify_hp_amount
1170 || combo_class_buf[c2.type].modify_hp_amount;
1171
1172 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1173
1174 if(dmg)
1175 {
1176 if (bridgedetected <= 0)
1177 {
1178 for(int32_t k=0; k<16; k+=2)
1179 for(int32_t j=0; j<16; j+=2)
1180 if(((k+j)/2)%2)
1181 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1182 }
1183 else
1184 {
1185 for(int32_t i=0; i<4; i++)
1186 {
1187 if (!(bridgedetected & (1<<i)))
1188 {
1189 int32_t tx=((i&2)<<2)+x;
1190 int32_t ty=((i&1)<<3)+y;
1191 for(int32_t k=0; k<8; k+=2)
1192 for(int32_t j=0; j<8; j+=2)
1193 if(((k+j)/2)%2)
1194 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1195 }
1196 }
1197 }
1198 }
1199
1200 if(c.type == cSLOPE)
1201 {
1202 slope_info s(c, x, y);
1203 s.draw(dest, 0, 0, COLOR_SLOPE);
1204 }
1205 auto fl0 = MAPFLAG2(-1,cx,cy);
1206 auto fl1 = MAPFLAG2(0,cx,cy);
1207 auto fl2 = MAPFLAG2(1,cx,cy);
1208 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1209 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1210 {
1211 bool top = false;
1212 if(cy)
1213 {
1214 top = true;
1215 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1216 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1219 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1221 {
1222 top = false;
1223 }
1224 }
1225 draw_ladder(dest,x,y,COLOR_LADDER,top);
1226 }
1227 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1228 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1229 {
1230 draw_platform(dest,x,y,COLOR_LADDER);
1231 }
1232 }
1233
1234 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1235 {
1236 int32_t cx = COMBOX(pos);
1237 int32_t cy = COMBOY(pos);
1238
1239 if (screen < 0) return;
1240 if (map < 0) return;
1241
1242 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1243
1244 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1245
1246 int32_t bridgedetected = 0;
1247 for(int32_t i=0; i<4; i++)
1248 {
1249 int32_t tx=((i&2)<<2)+x;
1250 int32_t ty=((i&1)<<3)+y;
1251 int32_t tx2=((i&2)<<2)+cx;
1252 int32_t ty2=((i&1)<<3)+cy;
1253 for (int32_t m = layer; m <= 1; m++)
1254 {
1255 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1256 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1257 {
1258 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1259 {
1260 bridgedetected |= (1<<i);
1261 }
1262 }
1263 else
1264 {
1265 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1266 {
1267 bridgedetected |= (1<<i);
1268 }
1269 }
1270 }
1271 if (bridgedetected & (1<<i))
1272 {
1273 continue;
1274 }
1275 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1276 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1277
1278
1279 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1280 {
1281 for(int32_t k=0; k<8; k+=2)
1282 for(int32_t j=0; j<8; j+=2)
1283 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1284 }
1285 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1286 {
1287 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1288 {
1289 for(int32_t k=0; k<8; k+=2)
1290 for(int32_t j=0; j<8; j+=2)
1291 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1292 }
1293 else
1294 {
1295 int32_t color = COLOR_SOLID;
1296
1297 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1298 color=vc(6);
1299 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1300 color=vc(7);
1301
1302 rectfill(dest,tx,ty,tx+7,ty+7,color);
1303 }
1304 }
1305 }
1306
1307 bridgedetected = 0;
1308 for(int32_t i=0; i<4; i++)
1309 {
1310 int32_t tx2=((i&2)<<2)+cx;
1311 int32_t ty2=((i&1)<<3)+cy;
1312 for (int32_t m = 0; m <= 1; m++)
1313 {
1314 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1315 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1316 {
1317 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1318 {
1319 bridgedetected |= (1<<i);
1320 }
1321 }
1322 else
1323 {
1324 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1325 {
1326 bridgedetected |= (1<<i);
1327 }
1328 }
1329 }
1330 }
1331
1332 // Draw damage combos
1333 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1334 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1335 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1336 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1337 || combo_class_buf[c1.type].modify_hp_amount
1338 || combo_class_buf[c2.type].modify_hp_amount;
1339
1340 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1341
1342 if(dmg)
1343 {
1344 if (bridgedetected <= 0)
1345 {
1346 for(int32_t k=0; k<16; k+=2)
1347 for(int32_t j=0; j<16; j+=2)
1348 if(((k+j)/2)%2)
1349 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1350 }
1351 else
1352 {
1353 for(int32_t i=0; i<4; i++)
1354 {
1355 if (!(bridgedetected & (1<<i)))
1356 {
1357 int32_t tx=((i&2)<<2)+x;
1358 int32_t ty=((i&1)<<3)+y;
1359 for(int32_t k=0; k<8; k+=2)
1360 for(int32_t j=0; j<8; j+=2)
1361 if(((k+j)/2)%2)
1362 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1363 }
1364 }
1365 }
1366 }
1367
1368 if(c.type == cSLOPE)
1369 {
1370 slope_info s(c, x, y);
1371 s.draw(dest, 0, 0, COLOR_SLOPE);
1372 }
1373 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1374 auto fl1 = MAPFLAG3(map,screen,0,pos);
1375 auto fl2 = MAPFLAG3(map,screen,1,pos);
1376 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1377 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1378 {
1379 bool top = false;
1380 if(cy)
1381 {
1382 top = true;
1383 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1384 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1389 {
1390 top = false;
1391 }
1392 }
1393 draw_ladder(dest,x,y,COLOR_LADDER,top);
1394 }
1395 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1396 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1397 {
1398 draw_platform(dest,x,y,COLOR_LADDER);
1399 }
1400 }
1401
1402 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1403 {
1404 const newcombo& c = combobuf[cmbdat];
1405
1406 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1407
1408 for(int32_t i=0; i<4; i++)
1409 {
1410 int32_t tx=((i&2)<<2)+x;
1411 int32_t ty=((i&1)<<3)+y;
1412
1413 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1414 {
1415 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1416 {
1417 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1418 }
1419 else
1420 {
1421 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1422 }
1423 }
1424
1425
1426 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1427 {
1428 for(int32_t k=0; k<8; k+=2)
1429 for(int32_t j=0; j<8; j+=2)
1430 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1431 }
1432 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1433 {
1434 if(c.type==cLADDERHOOKSHOT)
1435 {
1436 for(int32_t k=0; k<8; k+=2)
1437 for(int32_t j=0; j<8; j+=2)
1438 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1439 }
1440 else
1441 {
1442 int32_t color = COLOR_SOLID;
1443
1444 if(c.type==cLADDERONLY)
1445 color=vc(6);
1446 else if(c.type==cHOOKSHOTONLY)
1447 color=vc(7);
1448
1449 rectfill(dest,tx,ty,tx+7,ty+7,color);
1450 }
1451 }
1452
1453 // Draw damage combos
1454 if(combo_class_buf[c.type].modify_hp_amount != 0)
1455 {
1456 for(int32_t k=0; k<8; k+=2)
1457 for(int32_t j=0; j<8; j+=2)
1458 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1459 }
1460 }
1461
1462 if(c.type == cSLOPE)
1463 {
1464 slope_info s(c, 0, 0);
1465 zfix const& slope = s.slope();
1466
1467 BITMAP* sub = create_bitmap_ex(8,16,16);
1468 clear_bitmap(sub);
1469 s.draw(sub, 0, 0, COLOR_SLOPE);
1470 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1471 destroy_bitmap(sub);
1472 }
1473 if(c.flag == mfSIDEVIEWLADDER)
1474 {
1475 draw_ladder(dest,x,y,COLOR_LADDER);
1476 }
1477 else if(c.flag == mfSIDEVIEWPLATFORM)
1478 {
1479 draw_platform(dest,x,y,COLOR_LADDER);
1480 }
1481 }
1482
1483 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1484 {
1485 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1486 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1487 }
1488 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1489 {
1490 newcombo const& c = combobuf[cmbdat];
1491
1492 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1493 {
1494 if(sflag)
1495 {
1496 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1497 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1498 }
1499
1500 if(c.flag)
1501 {
1502 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1503 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1504 }
1505 }
1506
1507 if(flags&cCSET)
1508 {
1509 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1510 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1511 }
1512 else if(flags&cCTYPE)
1513 {
1514 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1515 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1516 }
1517 }
1518
1519 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1520 {
1521 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1522
1523 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1524 if(repos)
1525 {
1526 combotile_override_x = x+(8*(scale-1));
1527 combotile_override_y = y+(8*(scale-1));
1528 }
1529 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1530 if(repos) combotile_override_x = combotile_override_y = -1;
1531 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1532 destroy_bitmap(b);
1533 }
1534 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1535 {
1536 static newcombo nilcombo;
1537 nilcombo.tile = 0;
1538
1539 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1540
1541 if(c.tile==0)
1542 {
1543 rectfill(dest,x,y,x+15,y+15,vc(0));
1544 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1545 return;
1546 }
1547
1548 putcombo(dest,x,y,cmbdat,cset);
1549
1550 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1551 {
1552 if(sflag)
1553 {
1554 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1555 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1556 }
1557
1558 if(combobuf[cmbdat].flag)
1559 {
1560 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1561 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1562 }
1563 }
1564
1565 if(flags&cWALK)
1566 {
1567 put_walkflags(dest,x,y,cmbdat,0);
1568 }
1569
1570 if(flags&cCSET)
1571 {
1572 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1573 // text_mode(inv?vc(15):vc(0));
1574 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1575 }
1576 else if(flags&cCTYPE)
1577 {
1578 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1579 // text_mode(inv?vc(15):vc(0));
1580 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1581 }
1582 }
1583 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1584 {
1585 auto blitx = 1 + (slot % 16) * 17;
1586 auto blity = 1 + (slot / 16) * 17;
1587 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1588 }
1589
1590
1591 void copy_mapscr(mapscr *dest, const mapscr *src)
1592 {
1593 if(!dest || !src) return;
1594 *dest = *src;
1595 }
1596
1597 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1598 {
1599 int32_t x=0,y=0;
1600 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1601
1602 switch(side)
1603 {
1604 case up:
1605 case down:
1606 x=((pos&15)<<4)+xofs;
1607 y=(ignorepos?0:(pos&0xF0))+yofs;
1608 break;
1609
1610 case left:
1611 case right:
1612 x=(ignorepos?0:((pos&15)<<4))+xofs;
1613 y=(pos&0xF0)+yofs;
1614 break;
1615 }
1616
1617 switch(type)
1618 {
1619 case dt_lock:
1620 case dt_shut:
1621 case dt_boss:
1622 case dt_bomb:
1623 switch(side)
1624 {
1625 case up:
1626 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1627 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1628 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1629 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1630 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1631 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1632 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1633 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1634 break;
1635
1636 case down:
1637 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1638 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1639 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1640 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1641 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1642 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1643 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1644 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1645 break;
1646
1647 case left:
1648 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1649 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1650 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1651 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1652 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1653 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1654
1655 if(x+16 >= dest->w)
1656 break;
1657
1658 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1659 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1660 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1661 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1662 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1663 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1664 break;
1665
1666 case right:
1667
1668 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1669 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1670 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1671 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1672 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1673 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1674
1675 if(x+16 <= 0)
1676 break;
1677
1678 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1679 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1680 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1681 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1682 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1683 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1684 break;
1685 }
1686
1687 break;
1688
1689 case dt_pass:
1690 case dt_wall:
1691 case dt_walk:
1692 default:
1693 break;
1694 }
1695 }
1696
1697 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1698 {
1699 int32_t x=((pos&15)<<4)+xofs;
1700 int32_t y=(pos&0xF0)+yofs;
1701 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1702
1703
1704 switch(side)
1705 {
1706 case up:
1707 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1708 {
1709 overcombo(dest,x,y,
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1712 }
1713
1714 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1715 {
1716 overcombo(dest,x+16,y,
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1718
1719 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1720 }
1721
1722 break;
1723
1724 case down:
1725 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1726 {
1727 overcombo(dest,x,y,
1728 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1730 }
1731
1732 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1733 {
1734 overcombo(dest,x+16,y,
1735 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1736 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1737 }
1738
1739 break;
1740
1741 case left:
1742 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1743 {
1744 overcombo(dest,x,y,
1745 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1747 }
1748
1749 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1750 {
1751 overcombo(dest,x,y+16,
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1754 }
1755
1756 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1757 {
1758 overcombo(dest,x,y+32,
1759 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1760 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1761 }
1762
1763 break;
1764
1765 case right:
1766 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1767 {
1768 overcombo(dest,x,y,
1769 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1771 }
1772
1773 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1774 {
1775 overcombo(dest,x,y+16,
1776
1777 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1779 }
1780
1781 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1782 {
1783 overcombo(dest,x,y+32,
1784 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1785 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1786 }
1787
1788 break;
1789 }
1790 }
1791
1792 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1793 {
1794 word cmbcheck1, cmbcheck2;
1795 newcombo combocheck1, combocheck2;
1796 combocheck1 = combobuf[0];
1797 combocheck2 = combobuf[0];
1798 combocheck1.walk = 0;
1799 combocheck2.walk = 0;
1800
1801 int32_t layermap, layerscreen;
1802
1803 switch(dir)
1804 {
1805 case up:
1806 {
1807 if(i>15) //not top row of combos
1808 {
1809 return false;
1810 }
1811
1812 if(screen<16) //top row of screens
1813 {
1814 return false;
1815
1816 }
1817
1818 //check main screen
1819 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1820 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1821 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1822 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1823
1824 //check layer 1
1825 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1826
1827 if(layermap>-1 && layermap<map_count)
1828 {
1829 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1830 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1831 if (combobuf[cmbcheck1].type == cBRIDGE)
1832 {
1833 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1834 {
1835 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1836 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1837 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1838 }
1839 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1840 }
1841 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1842 }
1843
1844 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1845
1846 if(layermap>-1 && layermap<map_count)
1847 {
1848 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1849 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1850 if (combobuf[cmbcheck2].type == cBRIDGE)
1851 {
1852 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1853 {
1854 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1855 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1856 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1857 }
1858 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1859 }
1860 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1861 }
1862
1863 //check layer 2
1864 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1865
1866 if(layermap>-1 && layermap<map_count)
1867 {
1868 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1869
1870 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1871 if (combobuf[cmbcheck2].type == cBRIDGE)
1872 {
1873 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1874 {
1875 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1876 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1877 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1878 }
1879 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1880 }
1881 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1882 }
1883
1884 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1885
1886 if(layermap>-1 && layermap<map_count)
1887 {
1888 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1889 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1890 if (combobuf[cmbcheck2].type == cBRIDGE)
1891 {
1892 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1893 {
1894 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1895 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1896 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1897 }
1898 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1899 }
1900 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1901 }
1902
1903 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1904 {
1905 return true;
1906 }
1907
1908 break;
1909 }
1910 case down:
1911 {
1912 if(i<160) //not bottom row of combos
1913 {
1914 return false;
1915 }
1916
1917 if(screen>111) //bottom row of screens
1918 {
1919 return false;
1920 }
1921
1922 //check main screen
1923 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1924 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1925 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1926 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1927
1928
1929 //check layer 1
1930 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1931
1932 if(layermap>-1 && layermap<map_count)
1933 {
1934 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1935 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1936 if (combobuf[cmbcheck1].type == cBRIDGE)
1937 {
1938 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1939 {
1940 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1941 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1942 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1943 }
1944 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1945 }
1946 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1947 }
1948
1949 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1950
1951 if(layermap>-1 && layermap<map_count)
1952 {
1953 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1954 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1955 if (combobuf[cmbcheck2].type == cBRIDGE)
1956 {
1957 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1958 {
1959 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1960 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1961 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1962 }
1963 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1964 }
1965 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1966 }
1967
1968 //check layer 2
1969 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1970
1971 if(layermap>-1 && layermap<map_count)
1972 {
1973 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1974 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1975 if (combobuf[cmbcheck1].type == cBRIDGE)
1976 {
1977 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1978 {
1979 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1980 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1981 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1982 }
1983 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1984 }
1985 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1986 }
1987
1988 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1989
1990 if(layermap>-1 && layermap<map_count)
1991 {
1992 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1993 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1994 if (combobuf[cmbcheck2].type == cBRIDGE)
1995 {
1996 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1997 {
1998 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1999 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2000 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2001 }
2002 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2003 }
2004 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2005 }
2006
2007 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2008 {
2009 return true;
2010 }
2011
2012 break;
2013 }
2014 case left:
2015 {
2016 if((i&0xF)!=0) //not left column of combos
2017 {
2018 return false;
2019 }
2020
2021 if((screen&0xF)==0) //left column of screens
2022 {
2023 return false;
2024 }
2025
2026 //check main screen
2027 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2028 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2029 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2030 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2031
2032 //check layer 1
2033 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2034
2035 if(layermap>-1 && layermap<map_count)
2036 {
2037 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2038 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2039 if (combobuf[cmbcheck1].type == cBRIDGE)
2040 {
2041 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2042 {
2043 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2044 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2045 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2046 }
2047 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2048 }
2049 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2050 }
2051
2052 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2053
2054 if(layermap>-1 && layermap<map_count)
2055 {
2056 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2057 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2058 if (combobuf[cmbcheck2].type == cBRIDGE)
2059 {
2060 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2061 {
2062 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2063 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2064 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2065 }
2066 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2067 }
2068 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2069 }
2070
2071 //check layer 2
2072 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2073
2074 if(layermap>-1 && layermap<map_count)
2075 {
2076 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2077 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2078 if (combobuf[cmbcheck1].type == cBRIDGE)
2079 {
2080 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2081 {
2082 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2083 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2084 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2085 }
2086 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2087 }
2088 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2089 }
2090
2091 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2092
2093 if(layermap>-1 && layermap<map_count)
2094 {
2095 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2096 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2097 if (combobuf[cmbcheck2].type == cBRIDGE)
2098 {
2099 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2100 {
2101 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2102 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2103 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2104 }
2105 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2106 }
2107 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2108 }
2109
2110 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2111 {
2112 return true;
2113 }
2114
2115 break;
2116 }
2117 case right:
2118 {
2119 if((i&0xF)!=15) //not right column of combos
2120 {
2121 return false;
2122 }
2123
2124 if((screen&0xF)==15) //right column of screens
2125 {
2126 return false;
2127 }
2128
2129 //check main screen
2130 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2131 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2132 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2133 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2134
2135 //check layer 1
2136 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2137
2138 if(layermap>-1 && layermap<map_count)
2139 {
2140 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2141 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2142 if (combobuf[cmbcheck1].type == cBRIDGE)
2143 {
2144 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2145 {
2146 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2147 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2148 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2149 }
2150 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2151 }
2152 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2153 }
2154
2155 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2156
2157 if(layermap>-1 && layermap<map_count)
2158 {
2159 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2160 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2161 if (combobuf[cmbcheck2].type == cBRIDGE)
2162 {
2163 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2164 {
2165 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2166 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2167 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2168 }
2169 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2170 }
2171 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2172 }
2173
2174 //check layer 2
2175 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2176
2177 if(layermap>-1 && layermap<map_count)
2178 {
2179 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2180 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2181 if (combobuf[cmbcheck1].type == cBRIDGE)
2182 {
2183 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2184 {
2185 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2186 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2187 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2188 }
2189 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2190 }
2191 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2192 }
2193
2194 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2195
2196 if(layermap>-1 && layermap<map_count)
2197 {
2198 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2199
2200 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2201 if (combobuf[cmbcheck2].type == cBRIDGE)
2202 {
2203 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2204 {
2205 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2206 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2207 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2208 }
2209 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2210 }
2211 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2212 }
2213
2214 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2215 {
2216 return true;
2217 }
2218
2219 break;
2220 }
2221 }
2222
2223 return false;
2224 }
2225
2226 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2227 {
2228 int32_t checkcombo;
2229
2230 if(alignment_arrow_timer>31)
2231 {
2232 if(scr<0)
2233 {
2234 scr=cursor.screen;
2235 }
2236
2237 if((scr<128)) //do the misalignment arrows
2238 {
2239 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2240 {
2241 if(misaligned(cursor.map, scr, checkcombo, up))
2242 {
2243 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2244 }
2245 }
2246
2247 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2248 {
2249 if(misaligned(cursor.map, scr, checkcombo, down))
2250 {
2251 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2252 }
2253 }
2254
2255 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2256 {
2257 if(misaligned(cursor.map, scr, checkcombo, left))
2258 {
2259 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2260 }
2261 }
2262
2263 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2264 {
2265 if(misaligned(cursor.map, scr, checkcombo, right))
2266 {
2267 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2268 }
2269 }
2270
2271 int32_t tempalign;
2272
2273 //check top left corner
2274 checkcombo=0;
2275 tempalign=0;
2276 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2277 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2278
2279 switch(tempalign)
2280 {
2281 case 0:
2282 break;
2283
2284 case 1: //up
2285 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2286 break;
2287
2288 case 2: //left
2289 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2290 break;
2291
2292 case 3: //up-left
2293 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2294 break;
2295 }
2296
2297 //check top right corner
2298 checkcombo=15;
2299 tempalign=0;
2300 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2301 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2302
2303 switch(tempalign)
2304 {
2305 case 0:
2306 break;
2307
2308 case 1: //up
2309 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2310 break;
2311
2312 case 2: //right
2313 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2314 break;
2315
2316 case 3: //up-right
2317 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2318 break;
2319 }
2320
2321 //check bottom left corner
2322 checkcombo=160;
2323 tempalign=0;
2324 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2325 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2326
2327 switch(tempalign)
2328 {
2329 case 0:
2330 break;
2331
2332 case 1: //down
2333 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2334 break;
2335
2336 case 2: //left
2337 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2338 break;
2339
2340 case 3: //down-left
2341 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2342 break;
2343 }
2344
2345 //check bottom right corner
2346
2347 checkcombo=175;
2348 tempalign=0;
2349 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2350 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2351
2352 switch(tempalign)
2353 {
2354 case 0:
2355 break;
2356
2357 case 1: //down
2358 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2359 break;
2360
2361 case 2: //right
2362 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2363 break;
2364
2365 case 3: //down-right
2366 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2367 break;
2368 }
2369 }
2370 }
2371 }
2372
2373 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2374 {
2375 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2376 }
2377
2378 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2379 {
2380 if (map < 0 || screen < 0) return 0;
2381
2382 if(pos>175 || pos < 0)
2383 return 0;
2384
2385 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2386
2387 if (!m->is_valid()) return 0;
2388
2389 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2390
2391 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2392
2393 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2394
2395 if (!scr->is_valid()) return 0;
2396
2397 return scr->data[pos]; // entire combo code
2398 }
2399
2400 // Takes array index layer num., not actual layer num.
2401 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2402 {
2403 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2404
2405 if(map<0)
2406 map=cursor.map;
2407
2408 if(scr<0)
2409 scr=cursor.screen;
2410
2411 mapscr *screen1;
2412
2413 if(prv_mode)
2414 {
2415 screen1=get_prvscr();
2416 }
2417 else
2418 {
2419 screen1=AbsoluteScr(cursor.map,cursor.screen);
2420 }
2421
2422 int32_t layermap;
2423 layermap=screen1->layermap[lyr]-1;
2424
2425 if(layermap<0 || layermap >= map_count) return 0;
2426
2427 mapscr *layer;
2428
2429 if(prv_mode)
2430 layer = &prvlayers[lyr];
2431 else
2432 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2433
2434 int32_t pos = COMBOPOS(x,y);
2435
2436 if(pos>175 || pos < 0)
2437 return 0;
2438
2439 return layer->data[pos];
2440 }
2441
2442 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2443 {
2444 if(map<0)
2445 map=cursor.map;
2446
2447 if(scr<0)
2448 scr=cursor.screen;
2449
2450 mapscr *screen1;
2451
2452 if(prv_mode)
2453 {
2454 screen1=get_prvscr();
2455 }
2456 else
2457 {
2458 screen1=AbsoluteScr(cursor.map,cursor.screen);
2459 }
2460
2461 x = vbound(x, 0, 16*16);
2462 y = vbound(y, 0, 11*16);
2463 int32_t combo = COMBOPOS(x,y);
2464
2465 if(combo>175 || combo < 0)
2466 return 0;
2467
2468 return screen1->data[combo];
2469 }
2470
2471 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2472 {
2473 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2474 }
2475
2476 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2477 {
2478 if (map < 0 || screen < 0) return 0;
2479
2480 if(pos>175 || pos < 0)
2481 return 0;
2482
2483 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2484
2485 if (!m->is_valid()) return 0;
2486
2487 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2488
2489 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2490
2491 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2492
2493 if (!scr->is_valid()) return 0;
2494
2495 return scr->sflag[pos]; // entire combo code
2496 }
2497
2498 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2499 {
2500 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2501
2502 if(map<0)
2503 map=cursor.map;
2504
2505 if(scr<0)
2506 scr=cursor.screen;
2507
2508 mapscr *screen1;
2509
2510 if(prv_mode)
2511 {
2512 screen1=get_prvscr();
2513 }
2514 else
2515 {
2516 screen1=AbsoluteScr(cursor.map,cursor.screen);
2517 }
2518
2519 int32_t layermap;
2520 layermap=screen1->layermap[lyr]-1;
2521
2522 if(layermap<0 || layermap >= map_count) return 0;
2523
2524 mapscr *layer;
2525
2526 if(prv_mode)
2527 layer = &prvlayers[lyr];
2528 else
2529 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2530
2531 int32_t combo = COMBOPOS(x,y);
2532
2533 if(combo>175 || combo < 0)
2534 return 0;
2535
2536 return layer->sflag[combo];
2537 }
2538
2539 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2540 {
2541 if(map<0)
2542 map=cursor.map;
2543
2544 if(scr<0)
2545 scr=cursor.screen;
2546
2547 mapscr *screen1;
2548
2549 if(prv_mode)
2550 {
2551 screen1=get_prvscr();
2552 }
2553 else
2554 {
2555 screen1=AbsoluteScr(cursor.map,cursor.screen);
2556 }
2557
2558 x = vbound(x, 0, 16*16);
2559 y = vbound(y, 0, 11*16);
2560 int32_t combo = COMBOPOS(x,y);
2561
2562 if(combo>175 || combo < 0)
2563 return 0;
2564
2565 return screen1->sflag[combo];
2566 }
2567
2568 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2569 {
2570 mapscr *layers[7];
2571 mapscr *basescr;
2572 if(prv_mode)
2573 {
2574 layers[0] = &prvscr;
2575 basescr = layers[0];
2576 for(auto q = 1; q < 7; ++q)
2577 {
2578 if(prvlayers[q-1].valid)
2579 layers[q] = &(prvlayers[q-1]);
2580 else layers[q] = NULL;
2581 }
2582 }
2583 else
2584 {
2585 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2586 basescr = layers[0];
2587 for(auto q = 1; q < 7; ++q)
2588 {
2589 int32_t lmap = basescr->layermap[q-1]-1;
2590 int32_t lscr = basescr->layerscreen[q-1];
2591 if(lmap < 0)
2592 layers[q] = NULL;
2593 else layers[q] = AbsoluteScr(lmap, lscr);
2594 }
2595 }
2596 for(auto q = 0; q < 7; ++q)
2597 {
2598 if(!layers[q]) continue;
2599 for(auto pos = 0; pos < 176; ++pos)
2600 {
2601 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2602 if(cmb.type == cTORCH)
2603 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2604 }
2605 }
2606 word maxffc = basescr->numFFC();
2607 for(auto q = 0; q < maxffc; ++q)
2608 {
2609 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2610 if(cmb.type == cTORCH)
2611 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2612 }
2613 }
2614
2615 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2616 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2617 {
2618 newcombo const& cmb = combobuf[cid];
2619 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2620 if(dither)
2621 {
2622 if (LayerDitherSz == 0)
2623 return;
2624 BITMAP* buf = create_bitmap_ex(8,16,16);
2625 clear_bitmap(buf);
2626 overcombo(buf,0,0,cid,cset);
2627 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2628 if(over)
2629 {
2630 if(transp)
2631 {
2632 color_map = trans_table2;
2633 draw_trans_sprite(dest, buf, x, y);
2634 color_map = trans_table;
2635 }
2636 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2637 }
2638 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2639 destroy_bitmap(buf);
2640 }
2641 else if(over)
2642 {
2643 if(transp)
2644 overcombotranslucent(dest,x,y,cid,cset,0);
2645 else overcombo(dest,x,y,cid,cset);
2646 }
2647 else put_combo(dest,x,y,cid,cset,flags,sflag);
2648 }
2649 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2650 {
2651 if(!md) return;
2652
2653 // These should only be drawn for the currently selected layer, not every layer.
2654 SETFLAG(flags, cCSET, false);
2655 SETFLAG(flags, cCTYPE, false);
2656
2657 for (int32_t i = 0; i < 176; i++)
2658 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2659 }
2660 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2661 {
2662 if(!md) return;
2663
2664 // These should only be drawn for the currently selected layer, not every layer.
2665 SETFLAG(flags, cCSET, false);
2666 SETFLAG(flags, cCTYPE, false);
2667
2668 for (int32_t i = 0; i < 176; i++)
2669 {
2670 int data = md->data[i];
2671 if(combo_class_buf[combobuf[data].type].overhead)
2672 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2673 }
2674 }
2675 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2676 {
2677 if(!LayerMaskInt[lyr])
2678 return nullptr;
2679 if(lyr == 0)
2680 return basescr;
2681 int layermap = basescr->layermap[lyr-1]-1;
2682
2683 if(layermap>-1 && layermap<map_count)
2684 {
2685 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2686 return &TheMaps[layerscreen];
2687 }
2688 return nullptr;
2689 }
2690 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2691 {
2692 int num_ffcs = basescr->numFFC();
2693 for(int32_t i=num_ffcs-1; i>=0; i--)
2694 {
2695 auto const& ff = basescr->ffcs[i];
2696 if(ff.data)
2697 {
2698 if(!(ff.flags&ffc_changer))
2699 {
2700 int32_t tx=(ff.x.getInt())+x;
2701 int32_t ty=(ff.y.getInt())+y;
2702
2703 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2704 {
2705 if(ff.flags&ffc_trans)
2706 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2707 else
2708 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2709 }
2710 }
2711 }
2712 }
2713 }
2714 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2715 {
2716 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2717 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2718 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2719
2720 if(map<0)
2721 map=cursor.map;
2722
2723 if(screen<0)
2724 screen=cursor.screen;
2725
2726 mapscr *basescr;
2727 mapscr* layers[7] = {nullptr};
2728
2729 if(prv_mode)
2730 {
2731 hl_layer = -1;
2732 basescr=get_prvscr();
2733 }
2734 else
2735 {
2736 basescr=AbsoluteScr(map,screen);
2737 }
2738 layers[0] = _zmap_get_lyr_checked(0,basescr);
2739 for(int lyr = 1; lyr < 7; ++lyr)
2740 {
2741 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2742 : _zmap_get_lyr_checked(lyr,basescr);
2743 }
2744
2745 if(!(basescr->valid&mVALID))
2746 {
2747 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2748 rectfill(dest,x,y,x+255,y+175,vc(1));
2749
2750 if(ShowMisalignments)
2751 {
2752 check_alignments(dest,x,y,screen);
2753 }
2754
2755 return;
2756 }
2757
2758 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2759 {
2760 byte bgfill = 0;
2761 if (LayerDitherBG > -1)
2762 bgfill = vc(LayerDitherBG);
2763 rectfill(dest,x,y,x+255,y+175,bgfill);
2764 }
2765
2766 if(olddraw)
2767 {
2768 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2769 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2770 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2771 }
2772 else for (int lyr = -7; lyr < -3; ++lyr)
2773 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2774
2775 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2776 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2777 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2778
2779 if(!olddraw)
2780 {
2781 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2782 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2783 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2784 }
2785 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2786
2787 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2788 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2789
2790
2791 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2792 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2793
2794 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2795 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2796 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2797
2798 struct DoorDrawData
2799 {
2800 int over_pos; // Position for over_door (dBOMB)
2801 int put_pos; // Position for put_door (standard doors)
2802 int walk_x; // Pre-calculated X offset for dWALK
2803 int walk_y; // Pre-calculated Y offset for dWALK
2804 };
2805
2806 static const DoorDrawData door_data[4] = {
2807 // over, put, walk_x, walk_y
2808 { 39, 7, 120, 16 }, // up
2809 { 135, 151, 120, 144 }, // down
2810 { 66, 64, 16, 80 }, // left
2811 { 77, 78, 224, 80 } // right
2812 };
2813
2814 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2815 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2816
2817 int32_t doortype[4];
2818 for(int32_t i=0; i<4; i++)
2819 {
2820 switch(basescr->door[i])
2821 {
2822 case dOPEN: doortype[i]=dt_pass; break;
2823 case dLOCKED: doortype[i]=dt_lock; break;
2824 case d1WAYSHUTTER:
2825 case dSHUTTER: doortype[i]=dt_shut; break;
2826 case dBOSS: doortype[i]=dt_boss; break;
2827 case dBOMB: doortype[i]=dt_bomb; break;
2828 default: doortype[i]=0; // Default or unhandled
2829 }
2830 }
2831
2832 for (int i = 0; i < 4; ++i)
2833 {
2834 const auto& d = door_data[i];
2835 const int current_door_type_id = basescr->door[i];
2836
2837 switch (current_door_type_id) {
2838 case dBOMB:
2839 // Draw bombable overlay, then fall through to draw the door
2840 over_door(dest, d.over_pos, i, x, y, false, screen);
2841 [[fallthrough]];
2842
2843 case dOPEN:
2844 case dLOCKED:
2845 case d1WAYSHUTTER:
2846 case dSHUTTER:
2847 case dBOSS:
2848 {
2849 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2850 break;
2851 }
2852
2853 case dWALK:
2854 if (walk_trans) {
2855 overcombo(dest, d.walk_x + x, d.walk_y + y,
2856 door_set.walkthroughcombo[i],
2857 door_set.walkthroughcset[i]);
2858 } else {
2859 put_combo(dest, d.walk_x + x, d.walk_y + y,
2860 door_set.walkthroughcombo[i],
2861 door_set.walkthroughcset[i], 0, 0);
2862 }
2863 break;
2864 }
2865 }
2866
2867 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2868 {
2869 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2870 }
2871
2872 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2873 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2874 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2875
2876 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2877 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2878
2879 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2880
2881 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2882 {
2883 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2884 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2885 }
2886 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2887 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2888
2889 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2890
2891 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2892 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2893 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2894
2895 int num_ffcs = basescr->numFFC();
2896 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2897 if(basescr->ffcs[i].data)
2898 if(basescr->ffcs[i].flags&ffc_changer)
2899 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2900
2901 if(flags&cWALK)
2902 {
2903 if(layers[0])
2904 for(int32_t i=0; i<176; i++)
2905 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2906
2907 for(int32_t k=0; k<2; k++)
2908 {
2909 if(layers[k+1])
2910 for(int32_t i=0; i<176; i++)
2911 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2912 }
2913 for(int32_t i=num_ffcs-1; i>=0; i--)
2914 {
2915 if(auto data = basescr->ffcs[i].data)
2916 {
2917 if(!(basescr->ffcs[i].flags&ffc_changer))
2918 {
2919 newcombo const& cmb = combobuf[data];
2920 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2921 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2922
2923 if(basescr->ffcs[i].flags&ffc_solid)
2924 {
2925 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2926 }
2927
2928 if(cmb.type == cSLOPE)
2929 {
2930 slope_info s(cmb, tx, ty);
2931 s.draw(dest, 0, 0, COLOR_SLOPE);
2932 }
2933 }
2934 }
2935 }
2936 }
2937
2938 if(flags&(cFLAGS|cCSET|cCTYPE))
2939 {
2940 if(LayerMaskInt[CurrentLayer]!=0)
2941 {
2942 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2943 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2944
2945 for(int32_t i=0; i<176; i++)
2946 {
2947 if(CurrentLayer==0)
2948 {
2949 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2950 }
2951 else
2952 {
2953 if(prv_mode)
2954 {
2955 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2956 }
2957 else if(basescr->layermap[CurrentLayer-1] > 0)
2958 {
2959 if(scr)
2960 {
2961 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2962 scr->data[i],
2963 scr->cset[i], flags,
2964 scr->sflag[i]);
2965 }
2966 }
2967 }
2968 }
2969 }
2970 }
2971
2972 int32_t dark = basescr->flags&cDARK;
2973
2974 if(dark && !(flags&cNODARK)
2975 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2976 {
2977 int col = vc(blackout_color);
2978 for(int32_t j=0; j<80; j++) {
2979 // Logic: ((i^j)&1)==0 means parity matches
2980 int start = (j&1);
2981 for(int32_t i=start; i<(80)-j; i+=2) {
2982 putpixel(dest,x+i,y+j,col);
2983 }
2984 }
2985 }
2986
2987 if(ShowMisalignments)
2988 {
2989 check_alignments(dest,x,y,screen);
2990 }
2991 }
2992
2993 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2994 {
2995 if(map<0)
2996 map=cursor.map;
2997
2998 if(scr<0)
2999 scr=cursor.screen;
3000
3001 mapscr* layer=AbsoluteScr(map,scr);
3002 int32_t layermap=0, layerscreen=0;
3003
3004 if(!(layer->valid&mVALID))
3005 {
3006 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3007 rectfill(dest,x,y,x+255,y+15,vc(1));
3008 return;
3009 }
3010
3011 int32_t dark = layer->flags&4;
3012
3013 if(LayerMaskInt[0]==0)
3014 {
3015 rectfill(dest,x,y,x+255,y+15,0);
3016 }
3017
3018 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3019 int order[2] = {2,1};
3020 if (olddraw) zc_swap(order[0],order[1]);
3021 for(int k : order)
3022 {
3023 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3024 {
3025 layermap=layer->layermap[k]-1;
3026
3027 if(layermap>-1 && layermap<map_count)
3028 {
3029 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3030
3031 for(int32_t i=c; i<(c&0xF0)+16; i++)
3032 {
3033 auto data = TheMaps[layerscreen].data[i];
3034 auto cs = TheMaps[layerscreen].cset[i];
3035 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3036 }
3037 }
3038 }
3039 }
3040
3041 if(LayerMaskInt[0]!=0)
3042 {
3043 for(int32_t i=c; i<(c&0xF0)+16; i++)
3044 {
3045 word cmbdat = (i < 176 ? layer->data[i] : 0);
3046 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3047 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3048 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3049 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3050 }
3051 }
3052
3053 for(int32_t k=0; k<2; k++)
3054 {
3055 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3056 {
3057 layermap=layer->layermap[k]-1;
3058
3059 if(layermap>-1 && layermap<map_count)
3060 {
3061 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3062
3063 for(int32_t i=c; i<(c&0xF0)+16; i++)
3064 {
3065 auto data = TheMaps[layerscreen].data[i];
3066 auto cs = TheMaps[layerscreen].cset[i];
3067 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3068 }
3069 }
3070 }
3071 }
3072
3073 int32_t doortype[4];
3074
3075 for(int32_t i=0; i<4; i++)
3076 {
3077 switch(layer->door[i])
3078 {
3079 case dOPEN:
3080 doortype[i]=dt_pass;
3081 break;
3082
3083 case dLOCKED:
3084 doortype[i]=dt_lock;
3085 break;
3086
3087 case d1WAYSHUTTER:
3088 case dSHUTTER:
3089 doortype[i]=dt_shut;
3090 break;
3091
3092 case dBOSS:
3093 doortype[i]=dt_boss;
3094 break;
3095
3096 case dBOMB:
3097 doortype[i]=dt_bomb;
3098 break;
3099 }
3100 }
3101
3102 if(c<16)
3103 {
3104 switch(layer->door[up])
3105 {
3106 case dBOMB:
3107 case dOPEN:
3108 case dLOCKED:
3109 case d1WAYSHUTTER:
3110 case dSHUTTER:
3111 case dBOSS:
3112 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3113 break;
3114 }
3115 }
3116 else if(c>159)
3117 {
3118 switch(layer->door[down])
3119 {
3120 case dBOMB:
3121 case dOPEN:
3122 case dLOCKED:
3123 case d1WAYSHUTTER:
3124 case dSHUTTER:
3125 case dBOSS:
3126 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3127 break;
3128 }
3129 }
3130
3131 for(int32_t k=2; k<4; k++)
3132 {
3133 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3134 {
3135 layermap=layer->layermap[k]-1;
3136
3137 if(layermap>-1 && layermap<map_count)
3138 {
3139 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3140
3141 for(int32_t i=c; i<(c&0xF0)+16; i++)
3142 {
3143 if(layer->layeropacity[k]<255)
3144 {
3145 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3146 }
3147 else
3148 {
3149 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3150 }
3151 }
3152 }
3153 }
3154 }
3155
3156 //Overhead L0
3157 if(LayerMaskInt[0]!=0)
3158 {
3159 for(int32_t i=c; i<(c&0xF0)+16; i++)
3160 {
3161 int32_t ct1=layer->data[i];
3162 int32_t ct3=combobuf[ct1].type;
3163
3164 if(combo_class_buf[ct3].overhead)
3165 {
3166 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3167 }
3168 }
3169 }
3170
3171 //Overhead L1/2
3172 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3173 {
3174 for(int32_t k = 0; k < 2; ++k)
3175 {
3176 if(LayerMaskInt[k+1]!=0)
3177 {
3178 layermap=layer->layermap[k]-1;
3179
3180 if(layermap>-1 && layermap<map_count)
3181 {
3182 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3183 for(int32_t i=c; i<(c&0xF0)+16; i++)
3184 {
3185 auto data = TheMaps[layerscreen].data[i];
3186 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3187 auto cs = TheMaps[layerscreen].cset[i];
3188 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3189 }
3190 }
3191 }
3192 }
3193 }
3194
3195 for(int32_t k=4; k<6; k++)
3196 {
3197 if(LayerMaskInt[k+1]!=0)
3198 {
3199 layermap=layer->layermap[k]-1;
3200
3201 if(layermap>-1 && layermap<map_count)
3202 {
3203 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3204
3205 for(int32_t i=c; i<(c&0xF0)+16; i++)
3206 {
3207 auto data = TheMaps[layerscreen].data[i];
3208 auto cs = TheMaps[layerscreen].cset[i];
3209 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3210 }
3211 }
3212 }
3213 }
3214
3215 if(flags&cWALK)
3216 {
3217 if(LayerMaskInt[0]!=0)
3218 {
3219 for(int32_t i=c; i<(c&0xF0)+16; i++)
3220 {
3221 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3222 }
3223 }
3224
3225 for(int32_t k=0; k<2; k++)
3226 {
3227 if(LayerMaskInt[k+1]!=0)
3228 {
3229 for(int32_t i=c; i<(c&0xF0)+16; i++)
3230 {
3231 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3232 }
3233 }
3234 }
3235 }
3236
3237 if(flags&(cFLAGS|cCSET|cCTYPE))
3238 {
3239 if(LayerMaskInt[CurrentLayer]!=0)
3240 {
3241 for(int32_t i=c; i<(c&0xF0)+16; i++)
3242 {
3243 if(CurrentLayer==0)
3244 {
3245 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3246 }
3247 else
3248 {
3249 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3250
3251 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3252 {
3253 if(i < 176)
3254 {
3255 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3256 TheMaps[_lscr].data[i],
3257 TheMaps[_lscr].cset[i], flags|dark,
3258 TheMaps[_lscr].sflag[i]);
3259 }
3260 else
3261 {
3262 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3263 }
3264 }
3265 }
3266 }
3267 }
3268
3269 /*
3270 if (LayerMaskInt[0]!=0) {
3271 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3272 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3273 }
3274 }
3275 */
3276 }
3277
3278 if(ShowMisalignments)
3279 {
3280 if(c<16)
3281 {
3282 check_alignments(dest,x,y,scr);
3283 }
3284 else if(c>159)
3285 {
3286 check_alignments(dest,x,y-160,scr);
3287 }
3288 }
3289 }
3290
3291 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3292 {
3293 if(map<0)
3294 map=cursor.map;
3295
3296 if(scr<0)
3297 scr=cursor.screen;
3298
3299 mapscr* layer=AbsoluteScr(map,scr);
3300 int32_t layermap=0, layerscreen=0;
3301
3302 if(!(layer->valid&mVALID))
3303 {
3304 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3305 rectfill(dest,x,y,x+15,y+175,vc(1));
3306 return;
3307 }
3308
3309 int32_t dark = layer->flags&4;
3310
3311 if(LayerMaskInt[0]==0)
3312 {
3313 rectfill(dest,x,y,x+15,y+175,0);
3314 }
3315
3316 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3317 int order[2] = {2,1};
3318 if (olddraw) zc_swap(order[0],order[1]);
3319 for(int k : order)
3320 {
3321 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3322 {
3323 layermap=layer->layermap[k]-1;
3324
3325 if(layermap>-1 && layermap<map_count)
3326 {
3327 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3328
3329 for(int32_t i=c; i<176; i+=16)
3330 {
3331 auto data = TheMaps[layerscreen].data[i];
3332 auto cs = TheMaps[layerscreen].cset[i];
3333 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3334 }
3335 }
3336 }
3337 }
3338
3339 if(LayerMaskInt[0]!=0)
3340 {
3341 for(int32_t i=c; i<176; i+=16)
3342 {
3343 word cmbdat = layer->data[i];
3344 byte cmbcset = layer->cset[i];
3345 int32_t cmbflag = layer->sflag[i];
3346 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3347 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3348 }
3349 }
3350
3351 for(int32_t k=0; k<2; k++)
3352 {
3353 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3354 {
3355 layermap=layer->layermap[k]-1;
3356
3357 if(layermap>-1 && layermap<map_count)
3358 {
3359 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3360
3361 for(int32_t i=c; i<176; i+=16)
3362 {
3363 auto data = TheMaps[layerscreen].data[i];
3364 auto cs = TheMaps[layerscreen].cset[i];
3365 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3366 }
3367 }
3368 }
3369 }
3370
3371 int32_t doortype[4];
3372
3373 for(int32_t i=0; i<4; i++)
3374 {
3375 switch(layer->door[i])
3376 {
3377 case dOPEN:
3378 doortype[i]=dt_pass;
3379 break;
3380
3381 case dLOCKED:
3382 doortype[i]=dt_lock;
3383 break;
3384
3385 case d1WAYSHUTTER:
3386 case dSHUTTER:
3387 doortype[i]=dt_shut;
3388 break;
3389
3390 case dBOSS:
3391 doortype[i]=dt_boss;
3392 break;
3393
3394 case dBOMB:
3395 doortype[i]=dt_bomb;
3396 break;
3397 }
3398 }
3399
3400 if((c&0x0F)==0)
3401 {
3402 switch(layer->door[left])
3403 {
3404
3405 case dBOMB:
3406 case dOPEN:
3407 case dLOCKED:
3408 case d1WAYSHUTTER:
3409 case dSHUTTER:
3410 case dBOSS:
3411 // put_door(dest,64,left,doortype[left],x+256,y,true);
3412 put_door(dest,64,left,doortype[left],x,y,true,scr);
3413 break;
3414 }
3415 }
3416 else if((c&0x0F)==15)
3417 {
3418 switch(layer->door[right])
3419 {
3420 case dBOMB:
3421 case dOPEN:
3422 case dLOCKED:
3423 case d1WAYSHUTTER:
3424 case dSHUTTER:
3425 case dBOSS:
3426 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3427 break;
3428 }
3429 }
3430
3431 for(int32_t k=2; k<4; k++)
3432 {
3433 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3434 {
3435 layermap=layer->layermap[k]-1;
3436
3437 if(layermap>-1 && layermap<map_count)
3438 {
3439 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3440
3441 for(int32_t i=c; i<176; i+=16)
3442 {
3443 auto data = TheMaps[layerscreen].data[i];
3444 auto cs = TheMaps[layerscreen].cset[i];
3445 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3446 }
3447 }
3448 }
3449 }
3450
3451 //Overhead L0
3452 if(LayerMaskInt[0]!=0)
3453 {
3454 for(int32_t i=c; i<176; i+=16)
3455 {
3456 auto data = TheMaps[layerscreen].data[i];
3457 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3458 auto cs = TheMaps[layerscreen].cset[i];
3459 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3460 }
3461 }
3462 //Overhead L1/2
3463 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3464 {
3465 for(int32_t k = 0; k < 2; ++k)
3466 {
3467 if(LayerMaskInt[k+1]!=0)
3468 {
3469 layermap=layer->layermap[k]-1;
3470
3471 if(layermap>-1 && layermap<map_count)
3472 {
3473 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3474 for(int32_t i=c; i<176; i+=16)
3475 {
3476 auto data = TheMaps[layerscreen].data[i];
3477 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3478 auto cs = TheMaps[layerscreen].cset[i];
3479 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3480 }
3481 }
3482 }
3483 }
3484 }
3485
3486
3487 for(int32_t k=4; k<6; k++)
3488 {
3489 if(LayerMaskInt[k+1]!=0)
3490 {
3491 layermap=layer->layermap[k]-1;
3492
3493 if(layermap>-1 && layermap<map_count)
3494 {
3495 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3496
3497 for(int32_t i=c; i<176; i+=16)
3498 {
3499 auto data = TheMaps[layerscreen].data[i];
3500 auto cs = TheMaps[layerscreen].cset[i];
3501 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3502 }
3503 }
3504 }
3505 }
3506
3507 if(flags&cWALK)
3508 {
3509 if(LayerMaskInt[0]!=0)
3510 {
3511 for(int32_t i=c&0xF; i<176; i+=16)
3512 {
3513 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3514 }
3515 }
3516
3517 for(int32_t k=0; k<2; k++)
3518 {
3519 if(LayerMaskInt[k+1]!=0)
3520 {
3521 for(int32_t i=c&0xF; i<176; i+=16)
3522 {
3523 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3524 }
3525 }
3526 }
3527 }
3528
3529 if(flags&(cFLAGS|cCSET|cCTYPE))
3530 {
3531 if(LayerMaskInt[CurrentLayer]!=0)
3532 {
3533 for(int32_t i=c; i<176; i+=16)
3534 {
3535 if(CurrentLayer==0)
3536 {
3537 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3538 }
3539 else
3540 {
3541 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3542
3543 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3544 {
3545 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3546 TheMaps[_lscr].data[i],
3547 TheMaps[_lscr].cset[i], flags|dark,
3548 TheMaps[_lscr].sflag[i]);
3549 }
3550 }
3551 }
3552 }
3553 }
3554
3555 if(ShowMisalignments)
3556 {
3557 if((c&0x0F)==0)
3558 {
3559 check_alignments(dest,x,y,scr);
3560 }
3561 else if((c&0x0F)==15)
3562 {
3563 check_alignments(dest,x-240,y,scr);
3564 }
3565 }
3566 }
3567
3568 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3569 {
3570 if(map<0)
3571 map=cursor.map;
3572
3573 if(scr<0)
3574 scr=cursor.screen;
3575
3576 mapscr* layer=AbsoluteScr(map,scr);
3577 int32_t layermap=0, layerscreen=0;
3578
3579 if(!(layer->valid&mVALID))
3580 {
3581 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3582 rectfill(dest,x,y,x+15,y+15,vc(1));
3583 return;
3584 }
3585
3586 int32_t dark = layer->flags&4;
3587
3588 if(LayerMaskInt[0]!=0)
3589 {
3590 rectfill(dest,x,y,x+15,y+15,0);
3591 }
3592
3593 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3594 int order[2] = {2,1};
3595 if (olddraw) zc_swap(order[0],order[1]);
3596 for(int k : order)
3597 {
3598 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3599 {
3600 layermap=layer->layermap[k]-1;
3601
3602 if(layermap>-1 && layermap<map_count)
3603 {
3604 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3605
3606 auto data = TheMaps[layerscreen].data[c];
3607 auto cs = TheMaps[layerscreen].cset[c];
3608 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3609 }
3610 }
3611 }
3612
3613 if(LayerMaskInt[0]!=0)
3614 {
3615 word cmbdat = layer->data[c];
3616 byte cmbcset = layer->cset[c];
3617 int32_t cmbflag = layer->sflag[c];
3618 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3619 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3620 }
3621
3622
3623 for(int32_t k=0; k<2; k++)
3624 {
3625 if(LayerMaskInt[k+1]!=0)
3626 {
3627 layermap=layer->layermap[k]-1;
3628
3629 if(layermap>-1 && layermap<map_count)
3630 {
3631 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3632
3633 auto data = TheMaps[layerscreen].data[c];
3634 auto cs = TheMaps[layerscreen].cset[c];
3635 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3636 }
3637 }
3638 }
3639
3640 for(int32_t k=2; k<4; k++)
3641 {
3642 if(LayerMaskInt[k+1]!=0)
3643 {
3644 layermap=layer->layermap[k]-1;
3645
3646 if(layermap>-1 && layermap<map_count)
3647 {
3648 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3649 auto data = TheMaps[layerscreen].data[c];
3650 auto cs = TheMaps[layerscreen].cset[c];
3651 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3652 }
3653 }
3654 }
3655
3656 //Overhead L0
3657 if(LayerMaskInt[0]!=0)
3658 {
3659 auto data = TheMaps[layerscreen].data[c];
3660 if(combo_class_buf[combobuf[data].type].overhead)
3661 {
3662 auto cs = TheMaps[layerscreen].cset[c];
3663 drawcombo(dest,x,y,data,cs,0,0);
3664 }
3665 }
3666 //Overhead L1/2
3667 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3668 {
3669 for(int32_t k = 0; k < 2; ++k)
3670 {
3671 if(LayerMaskInt[k+1]!=0)
3672 {
3673 layermap=layer->layermap[k]-1;
3674
3675 if(layermap>-1 && layermap<map_count)
3676 {
3677 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3678 auto data = TheMaps[layerscreen].data[c];
3679 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3680 auto cs = TheMaps[layerscreen].cset[c];
3681 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3682 }
3683 }
3684 }
3685 }
3686
3687
3688 for(int32_t k=4; k<6; k++)
3689 {
3690 if(LayerMaskInt[k+1]!=0)
3691 {
3692 layermap=layer->layermap[k]-1;
3693
3694 if(layermap>-1 && layermap<map_count)
3695 {
3696 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3697 auto data = TheMaps[layerscreen].data[c];
3698 auto cs = TheMaps[layerscreen].cset[c];
3699 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3700 }
3701 }
3702 }
3703
3704 if(flags&cWALK)
3705 {
3706 if(LayerMaskInt[0]!=0)
3707 {
3708 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3709 }
3710
3711 for(int32_t k=0; k<2; k++)
3712 {
3713 if(LayerMaskInt[k+1]!=0)
3714 {
3715 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3716 }
3717 }
3718 }
3719
3720 if(flags&(cFLAGS|cCSET|cCTYPE))
3721 {
3722 if(LayerMaskInt[CurrentLayer]!=0)
3723 {
3724 int32_t i = c;
3725 //for(int32_t i=c; i==c; i++)
3726 {
3727 if(CurrentLayer==0)
3728 {
3729 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3730 }
3731 else
3732 {
3733 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3734
3735 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3736 {
3737 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3738 TheMaps[_lscr].data[i],
3739 TheMaps[_lscr].cset[i], flags|dark,
3740 TheMaps[_lscr].sflag[i]);
3741 }
3742 }
3743 }
3744 }
3745 }
3746
3747 if(ShowMisalignments)
3748 {
3749 switch(c)
3750 {
3751 case 0:
3752 check_alignments(dest,x,y,scr);
3753 break;
3754
3755 case 15:
3756 check_alignments(dest,x-240,y,scr);
3757 break;
3758
3759 case 160:
3760 check_alignments(dest,x,y-160,scr);
3761 break;
3762
3763 case 175:
3764 check_alignments(dest,x-240,y-160,scr);
3765 break;
3766 }
3767 }
3768 }
3769
3770 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3771 {
3772 if (InvalidBG == 2)
3773 {
3774 draw_checkerboard(dest, x, y, 16);
3775 }
3776 else if(InvalidBG == 1)
3777 {
3778 draw_static(dest, x, y, 16, 16);
3779 }
3780 else
3781 {
3782 rectfill(dest, x, y, x+15, y+15, vc(0));
3783 rect(dest, x, y, x+15, y+15, vc(15));
3784 line(dest, x, y, x+15, y+15, vc(15));
3785 line(dest, x, y+15, x+15, y, vc(15));
3786 }
3787 }
3788
3789 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3790 {
3791 if (InvalidBG == 2)
3792 {
3793 for(int32_t q = 0; q < 11; ++q)
3794 draw_checkerboard(dest, x, y + q * 16, 16);
3795 }
3796 else if(InvalidBG == 1)
3797 {
3798 draw_static(dest, x, y, 16, 176);
3799 }
3800 else
3801 {
3802 rectfill(dest, x, y, x+15, y+175, vc(0));
3803 rect(dest, x, y, x+15, y+175, vc(15));
3804 line(dest, x, y, x+15, y+175, vc(15));
3805 line(dest, x, y+175, x+15, y, vc(15));
3806 }
3807 }
3808
3809 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3810 {
3811 if (InvalidBG == 2)
3812 {
3813 for (int32_t q = 0; q < 16; ++q)
3814 draw_checkerboard(dest, x + q * 16, y, 16);
3815 }
3816 else if(InvalidBG == 1)
3817 {
3818 draw_static(dest, x, y, 256, 16);
3819 }
3820 else
3821 {
3822 rectfill(dest, x, y, x+255, y+15, vc(0));
3823 rect(dest, x, y, x+255, y+15, vc(15));
3824 line(dest, x, y, x+255, y+15, vc(15));
3825 line(dest, x, y+15, x+255, y, vc(15));
3826 }
3827 }
3828
3829 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3830 {
3831 for(int32_t i=0; i<176; i++)
3832 {
3833 word cmbdat = screens[TEMPLATE].data[i];
3834 byte cmbcset = screens[TEMPLATE].cset[i];
3835 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3836 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3837 }
3838 }
3839
3840 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3841 {
3842 for(int32_t i=0; i<176; i++)
3843 {
3844 word cmbdat = screens[TEMPLATE2].data[i];
3845 byte cmbcset = screens[TEMPLATE2].cset[i];
3846 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3847 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3848 }
3849 }
3850
3851 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3852 {
3853 word cmbdat = screens[TEMPLATE].data[pos];
3854 byte cmbcset = screens[TEMPLATE].cset[pos];
3855 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3856 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3857 }
3858
3859 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3860 {
3861 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3862 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3863 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3864 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3865 }
3866
3867 void zmap::scroll(int32_t dir, bool warp)
3868 {
3869 if(cursor.map<map_count)
3870 {
3871 switch(dir)
3872 {
3873 case up:
3874 if(warp && Map.CurrScr()->flags2&wfUP)
3875 {
3876 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3877 }
3878 else if(cursor.screen>15)
3879 {
3880 setCurrScr(cursor.screen - 16);
3881 }
3882
3883 break;
3884
3885 case down:
3886 if(warp && Map.CurrScr()->flags2&wfDOWN)
3887 {
3888 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3889 }
3890 else if(cursor.screen<MAPSCRS-16)
3891 {
3892 setCurrScr(cursor.screen + 16);
3893 }
3894
3895 break;
3896
3897 case left:
3898 if(warp && Map.CurrScr()->flags2&wfLEFT)
3899 {
3900 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3901 }
3902 else if(cursor.screen&15)
3903 {
3904 setCurrScr(cursor.screen - 1);
3905 }
3906
3907 break;
3908
3909 case right:
3910 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3911 {
3912 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3913 }
3914 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3915 {
3916 setCurrScr(cursor.screen + 1);
3917 }
3918
3919 break;
3920 }
3921 }
3922 }
3923
3924 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3925 {
3926 switch(side)
3927 {
3928 case up:
3929 switch(door)
3930 {
3931 case dWALL:
3932 case dBOMB:
3933 case dWALK:
3934 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3935 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3936 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3937 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3938 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3939 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3940 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3941 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3942 break;
3943
3944 default:
3945 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3946 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3947 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3948 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3949 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3950 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3951 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3952 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3953 break;
3954 }
3955
3956 break;
3957
3958 case down:
3959 switch(door)
3960 {
3961 case dWALL:
3962 case dBOMB:
3963 case dWALK:
3964 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3965 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3966 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3967 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3968 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3969 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3970 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3971 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3972 break;
3973
3974 default:
3975 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3976 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3977 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3978 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3979 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3980 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3981 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3982 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3983 break;
3984 }
3985
3986 break;
3987
3988 case left:
3989 switch(door)
3990 {
3991 case dWALL:
3992 case dBOMB:
3993 case dWALK:
3994 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
3995 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
3996 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
3997 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
3998 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
3999 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4000 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4001 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4002 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4003 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4004 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4005 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4006 break;
4007
4008 default:
4009 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4010 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4011 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4012 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4013 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4014 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4015 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4016 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4017 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4018 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4019 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4020 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4021 break;
4022 }
4023
4024 break;
4025
4026 case right:
4027 switch(door)
4028 {
4029 case dWALL:
4030 case dBOMB:
4031 case dWALK:
4032 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4033 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4034 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4035 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4036 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4037 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4038 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4039 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4040 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4041 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4042 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4043 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4044 break;
4045
4046 default:
4047 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4048 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4049 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4050 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4051 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4052 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4053 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4054 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4055 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4056 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4057 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4058 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4059 break;
4060 }
4061
4062 break;
4063 }
4064 }
4065 void zmap::DoPutDoorCommand(int side, int door, bool force)
4066 {
4067 if(!force && screens[cursor.screen].door[side] == door)
4068 return;
4069 bool already_list = InListCommand();
4070 if(!already_list)
4071 StartListCommand();
4072 DoSetDoorCommand(cursor.screen,side,door);
4073 if(door != dNONE)
4074 {
4075 word data[176] = {0};
4076 byte cset[176] = {0};
4077 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4078 for(int q = 0; q < 176; ++q)
4079 if(data[q])
4080 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4081 }
4082 if(!already_list)
4083 FinishListCommand();
4084 }
4085 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4086 {
4087 if(screens[screen].door[side] == door)
4088 return;
4089
4090 screens[screen].door[side] = door;
4091 if(door != dNONE)
4092 {
4093 word data[176] = {0};
4094 byte cset[176] = {0};
4095 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4096 for(int q = 0; q < 176; ++q)
4097 if(data[q])
4098 {
4099 screens[screen].data[q] = data[q];
4100 screens[screen].cset[q] = cset[q];
4101 }
4102 }
4103 }
4104
4105 void list_command::execute()
4106 {
4107 for (auto command : commands)
4108 {
4109 command->execute();
4110 }
4111 }
4112
4113 void list_command::undo()
4114 {
4115 for (int i = commands.size() - 1; i >= 0; i--)
4116 {
4117 commands[i]->undo();
4118 }
4119 }
4120
4121 int list_command::size()
4122 {
4123 int s = 0;
4124 for (auto command : commands)
4125 {
4126 s += command->size();
4127 }
4128 return s;
4129 }
4130
4131 void set_combo_command::execute()
4132 {
4133 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4134 if (!scr_ptr) return;
4135
4136 if (combo != -1) scr_ptr->data[pos] = combo;
4137 scr_ptr->cset[pos] = cset;
4138 }
4139
4140 void set_combo_command::undo()
4141 {
4142 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4143 if(!mapscr_ptr) return;
4144 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4145 mapscr_ptr->cset[pos] = prev_cset;
4146 }
4147
4148 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4149 {
4150 std::array<int, 8> initd_arr;
4151 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4152
4153 return {
4154 .x = ffc.x,
4155 .y = ffc.y,
4156 .vx = ffc.vx,
4157 .vy = ffc.vy,
4158 .ax = ffc.ax,
4159 .ay = ffc.ay,
4160 .data = ffc.data,
4161 .cset = ffc.cset,
4162 .delay = ffc.delay,
4163 .link = ffc.link,
4164 .script = ffc.script,
4165 .tw = ffc.txsz,
4166 .th = ffc.tysz,
4167 .ew = ffc.hit_width,
4168 .eh = ffc.hit_height,
4169 .flags = ffc.flags,
4170 .initd = initd_arr,
4171 .layer = ffc.layer
4172 };
4173 }
4174
4175 void set_ffc_command::execute()
4176 {
4177 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4178 if(!mapscr_ptr) return;
4179
4180 mapscr_ptr->valid |= mVALID;
4181 mapscr_ptr->ffcs[i].x = data.x;
4182 mapscr_ptr->ffcs[i].y = data.y;
4183 mapscr_ptr->ffcs[i].vx = data.vx;
4184 mapscr_ptr->ffcs[i].vy = data.vy;
4185 mapscr_ptr->ffcs[i].ax = data.ax;
4186 mapscr_ptr->ffcs[i].ay = data.ay;
4187 mapscr_ptr->ffcs[i].data = data.data;
4188 mapscr_ptr->ffcs[i].cset = data.cset;
4189 mapscr_ptr->ffcs[i].delay = data.delay;
4190 mapscr_ptr->ffcs[i].link = data.link;
4191 mapscr_ptr->ffcs[i].script = data.script;
4192 mapscr_ptr->ffcs[i].flags = data.flags;
4193 mapscr_ptr->ffEffectWidth(i, data.ew);
4194 mapscr_ptr->ffEffectHeight(i, data.eh);
4195 mapscr_ptr->ffTileWidth(i, data.tw);
4196 mapscr_ptr->ffTileHeight(i, data.th);
4197 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4198 mapscr_ptr->ffcs[i].layer = data.layer;
4199 mapscr_ptr->ffcCountMarkDirty();
4200 mapscr_ptr->ffcs[i].updateSolid();
4201 }
4202
4203 void set_ffc_command::undo()
4204 {
4205 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4206 if(!mapscr_ptr) return;
4207
4208 mapscr_ptr->ffcs[i].x = prev_data.x;
4209 mapscr_ptr->ffcs[i].y = prev_data.y;
4210 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4211 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4212 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4213 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4214 mapscr_ptr->ffcs[i].data = prev_data.data;
4215 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4216 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4217 mapscr_ptr->ffcs[i].link = prev_data.link;
4218 mapscr_ptr->ffcs[i].script = prev_data.script;
4219 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4220 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4221 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4222 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4223 mapscr_ptr->ffTileHeight(i, prev_data.th);
4224 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4225 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4226 mapscr_ptr->ffcCountMarkDirty();
4227 mapscr_ptr->ffcs[i].updateSolid();
4228 }
4229
4230 void set_flag_command::execute()
4231 {
4232 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4233 if(!mapscr_ptr) return;
4234
4235 mapscr_ptr->valid |= mVALID;
4236 mapscr_ptr->sflag[pos] = flag;
4237 }
4238
4239 void set_flag_command::undo()
4240 {
4241 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4242 if(!mapscr_ptr) return;
4243 mapscr_ptr->sflag[pos] = prev_flag;
4244 }
4245
4246 void set_door_command::execute()
4247 {
4248 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4249 if(!mapscr_ptr) return;
4250
4251 mapscr_ptr->valid |= mVALID;
4252 mapscr_ptr->door[side] = door;
4253 }
4254
4255 void set_door_command::undo()
4256 {
4257 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4258 }
4259
4260 void set_dcs_command::execute()
4261 {
4262 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4263 if(!mapscr_ptr) return;
4264
4265 mapscr_ptr->valid |= mVALID;
4266 mapscr_ptr->door_combo_set = dcs;
4267 }
4268
4269 void set_dcs_command::undo()
4270 {
4271 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4272 }
4273
4274 void paste_screen_command::execute()
4275 {
4276 perform(screen.get());
4277 }
4278
4279 void paste_screen_command::undo()
4280 {
4281 if (prev_screens.size() > 1)
4282 {
4283 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4284 ASSERT(prev_screens.size() == 128);
4285 for (int i = 0; i < 128; i++)
4286 {
4287 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4288 // TODO: why not just this?
4289 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4290 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4291 }
4292 return;
4293 }
4294
4295 perform(prev_screens[0].get());
4296 }
4297
4298 int paste_screen_command::size()
4299 {
4300 return prev_screens.size() + 1;
4301 }
4302
4303 void paste_screen_command::perform(mapscr* to)
4304 {
4305 if (to)
4306 {
4307 switch (type) {
4308 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4309 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4310 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4311 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4312 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4313 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4314 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4315 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4316 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4317 case ScreenPartial: Map.Paste(*to, screen_index); break;
4318 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4319 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4320 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4321 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4322 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4323 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4324 }
4325 }
4326 else
4327 {
4328 Map.clearscr(screen_index);
4329 }
4330 refresh(rALL);
4331 }
4332
4333 void set_screen_command::execute()
4334 {
4335 if (screen)
4336 {
4337 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4338 }
4339 else
4340 {
4341 Map.clearscr(screen_index);
4342 }
4343 refresh(rALL);
4344 }
4345
4346 void set_screen_command::undo()
4347 {
4348 if (prev_screen)
4349 {
4350 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4351 }
4352 else
4353 {
4354 Map.clearscr(screen_index);
4355 }
4356 refresh(rALL);
4357 }
4358
4359 int set_screen_command::size()
4360 {
4361 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4362 }
4363
4364 static std::shared_ptr<list_command> current_list_command;
4365 void zmap::StartListCommand()
4366 {
4367 ASSERT(!current_list_command);
4368 current_list_command.reset(new list_command);
4369 }
4370
4371 void zmap::FinishListCommand()
4372 {
4373 if (current_list_command->commands.size() == 1)
4374 {
4375 input_undo_stack.push_back(current_list_command->commands[0]);
4376 }
4377 else if (current_list_command->commands.size() > 1)
4378 {
4379 input_undo_stack.push_back(current_list_command);
4380 }
4381 CapCommandHistory();
4382 current_list_command = nullptr;
4383 }
4384
4385 void zmap::RevokeListCommand()
4386 {
4387 current_list_command->undo();
4388 current_list_command = nullptr;
4389 }
4390
4391 bool zmap::InListCommand() const
4392 {
4393 return current_list_command ? true : false;
4394 }
4395
4396 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4397 {
4398 input_redo_stack = {};
4399
4400 if (!skip_execute) command->execute();
4401 if (current_list_command)
4402 {
4403 current_list_command->commands.push_back(command);
4404 if (current_list_command->commands.size() == 1)
4405 {
4406 current_list_command->cursor = command->cursor;
4407 }
4408 }
4409 else
4410 {
4411 input_undo_stack.push_back(command);
4412 CapCommandHistory();
4413 }
4414 mark_save_dirty();
4415 }
4416
4417 void zmap::UndoCommand()
4418 {
4419 if (input_undo_stack.size() <= 0) return;
4420
4421 // If not currently looking at the associated screen, first change the view
4422 // and wait for the next call to actually undo this command.
4423 auto command = input_undo_stack.back();
4424 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4425 {
4426 setCursor(command.get()->cursor);
4427 return;
4428 }
4429
4430 command->undo();
4431 input_redo_stack.push(command);
4432 input_undo_stack.pop_back();
4433 mark_save_dirty();
4434 }
4435
4436 void zmap::RedoCommand()
4437 {
4438 if (input_redo_stack.size() <= 0) return;
4439
4440 // If not currently selected the associated screen, first change the cursor
4441 // and wait for the next call to actually execute this command.
4442 auto command = input_redo_stack.top();
4443 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4444 {
4445 setCursor(command.get()->cursor);
4446 return;
4447 }
4448
4449 command->execute();
4450 input_undo_stack.push_back(command);
4451 input_redo_stack.pop();
4452 mark_save_dirty();
4453 }
4454
4455 11 void zmap::ClearCommandHistory()
4456 {
4457 11 current_list_command = nullptr;
4458 11 input_undo_stack = {};
4459 11 input_redo_stack = {};
4460 11 }
4461
4462 // Extra amount is from mapscr's vectors.
4463 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4464 // Allow the undo system to use roughly 100 MB of memory.
4465 // This doesn't count the memory used by commands that don't store a mapscr,
4466 // but that should be negligible.
4467 12 static int max_command_size = 100e6 / size_of_mapscr;
4468 void zmap::CapCommandHistory()
4469 {
4470 int size;
4471 do
4472 {
4473 size = 0;
4474 for (auto command : input_undo_stack)
4475 {
4476 size += command->size();
4477 }
4478 if (size > max_command_size) input_undo_stack.pop_front();
4479 } while (size > max_command_size);
4480 }
4481
4482 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4483 {
4484 if (!pos.is_valid(cursor))
4485 return;
4486
4487 int map = cursor.map;
4488 int screen = cursor.viewscr + pos.screen_offset();
4489 if (!AbsoluteScr(map, screen))
4490 return;
4491
4492 if (CurrentLayer)
4493 {
4494 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4495 map = scr->layermap[CurrentLayer-1]-1;
4496 screen = scr->layerscreen[CurrentLayer-1];
4497 }
4498 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4499 }
4500
4501 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4502 {
4503 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4504 if (!mapscr_ptr) return;
4505
4506 std::shared_ptr<set_combo_command> command(new set_combo_command);
4507 command->cursor = cursor;
4508 command->map = map;
4509 command->scr = scr;
4510 command->pos = pos;
4511 command->combo = combo;
4512 command->cset = cset;
4513 command->prev_combo = mapscr_ptr->data[pos];
4514 command->prev_cset = mapscr_ptr->cset[pos];
4515 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4516 {
4517 // nothing to do...
4518 return;
4519 }
4520
4521 ExecuteCommand(command);
4522 }
4523
4524 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4525 {
4526 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4527 if(!mapscr_ptr) return;
4528
4529 mapscr_ptr->ensureFFC(i);
4530
4531 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4532
4533 std::array<int, 8> initd_arr;
4534 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4535
4536 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4537
4538 command->cursor = cursor;
4539 command->map = map;
4540 command->scr = scr;
4541 command->i = i;
4542 command->data = data;
4543 command->prev_data = prev_data;
4544 if (data == prev_data)
4545 {
4546 // nothing to do...
4547 return;
4548 }
4549
4550 ExecuteCommand(command);
4551 }
4552
4553 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4554 {
4555 if (!pos.is_valid(cursor))
4556 return;
4557
4558 int map = cursor.map;
4559 int screen = cursor.viewscr + pos.screen_offset();
4560 if (!AbsoluteScr(map, screen))
4561 return;
4562
4563 if (CurrentLayer)
4564 {
4565 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4566 map = scr->layermap[CurrentLayer-1]-1;
4567 screen = scr->layerscreen[CurrentLayer-1];
4568 }
4569 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4570 }
4571
4572 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4573 {
4574 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4575 if(!mapscr_ptr) return;
4576
4577 std::shared_ptr<set_flag_command> command(new set_flag_command);
4578 command->cursor = cursor;
4579 command->map = map;
4580 command->scr = scr;
4581 command->pos = pos;
4582 command->flag = flag;
4583 command->prev_flag = mapscr_ptr->sflag[pos];
4584 if (command->flag == command->prev_flag)
4585 {
4586 // nothing to do...
4587 return;
4588 }
4589
4590 ExecuteCommand(command);
4591 }
4592
4593 void zmap::DoSetDoorCommand(int scr, int side, int door)
4594 {
4595 if(screens[scr].door[side] == door)
4596 return;
4597 std::shared_ptr<set_door_command> command(new set_door_command);
4598 command->cursor = cursor;
4599 command->side = side;
4600 command->door = door;
4601 command->prev_door = screens[scr].door[side];
4602
4603 ExecuteCommand(command);
4604 }
4605 void zmap::DoSetDCSCommand(int dcs)
4606 {
4607 if(screens[cursor.screen].door_combo_set == dcs)
4608 return;
4609 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4610 command->cursor = cursor;
4611 command->dcs = dcs;
4612 command->prev_dcs = screens[cursor.screen].door_combo_set;
4613
4614 ExecuteCommand(command);
4615 }
4616
4617 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4618 {
4619 if (screen == -1)
4620 screen = cursor.screen;
4621
4622 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4623 command->cursor = cursor;
4624 command->type = type;
4625 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4626 command->screen_index = screen;
4627
4628 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4629 {
4630 for (int i=0; i < 128; i++)
4631 {
4632 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4633 }
4634 }
4635 else
4636 {
4637 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4638 }
4639
4640 ExecuteCommand(command);
4641 }
4642
4643 void zmap::DoClearScreenCommand(int screen)
4644 {
4645 std::shared_ptr<set_screen_command> command(new set_screen_command);
4646 command->cursor = cursor;
4647 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4648 command->screen = std::shared_ptr<mapscr>(nullptr);
4649 command->screen_index = screen;
4650
4651 ExecuteCommand(command);
4652 }
4653
4654 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4655 {
4656 std::shared_ptr<set_screen_command> command(new set_screen_command);
4657 command->cursor = cursor;
4658 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4659 Template(floorcombo, floorcset, screen);
4660 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4661
4662 ExecuteCommand(command, true);
4663 }
4664
4665 void zmap::Copy(int scr)
4666 {
4667 if(screens[scr].valid&mVALID)
4668 {
4669 copy_mapscr(&copymapscr, &screens[scr]);
4670 //copymapscr=screens[scr];
4671 can_paste=true;
4672 copymap=cursor.map;
4673 copyscr=scr;
4674 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4675 copyffc = -1;
4676 }
4677 }
4678
4679 void zmap::CopyFFC(int32_t screen, int32_t n)
4680 {
4681 if(screens[screen].valid&mVALID)
4682 {
4683 copy_mapscr(&copymapscr, &screens[screen]);
4684 // Can't paste the screen itself
4685 can_paste = false;
4686 copymap=cursor.map;
4687 copyscr=screen;
4688 copyffc = n;
4689 }
4690 }
4691
4692 void zmap::Paste(const mapscr& copymapscr, int screen)
4693 {
4694 if(can_paste)
4695 {
4696 if(!(screens[screen].valid&mVALID))
4697 {
4698 screens[screen].valid |= mVALID;
4699 screens[screen].color = copymapscr.color;
4700 }
4701
4702 screens[screen].door_combo_set = copymapscr.door_combo_set;
4703
4704 for(int32_t i=0; i<4; i++)
4705 {
4706 screens[screen].door[i]=copymapscr.door[i];
4707 }
4708
4709 for(int32_t i=0; i<176; i++)
4710 {
4711 screens[screen].data[i] = copymapscr.data[i];
4712 screens[screen].cset[i] = copymapscr.cset[i];
4713 screens[screen].sflag[i] = copymapscr.sflag[i];
4714 }
4715
4716 refresh_color();
4717
4718 mark_save_dirty();
4719 }
4720 }
4721
4722 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4723 {
4724 if(can_paste)
4725 {
4726 screens[screen].undercombo = copymapscr.undercombo;
4727 screens[screen].undercset = copymapscr.undercset;
4728 mark_save_dirty();
4729 }
4730 }
4731
4732 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4733 {
4734 if(can_paste)
4735 {
4736 for(int32_t i=0; i<128; i++)
4737 {
4738 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4739 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4740 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4741 }
4742
4743 mark_save_dirty();
4744 }
4745 }
4746
4747 // TODO const mapscr& copymapscr
4748 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4749 {
4750 if(can_paste)
4751 {
4752 screens[screen].ffcs = copymapscr.ffcs;
4753 screens[screen].ffcCountMarkDirty();
4754 mark_save_dirty();
4755 }
4756 }
4757
4758 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4759 {
4760 if(can_paste)
4761 {
4762 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4763
4764 for(int32_t i=0; i<4; i++)
4765 {
4766 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4767 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4768 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4769 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4770 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4771 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4772 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4773 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4774 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4775 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4776 }
4777
4778 mark_save_dirty();
4779 }
4780 }
4781
4782 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4783 {
4784 if(can_paste)
4785 {
4786 screens[screen].csensitive = copymapscr.csensitive;
4787 screens[screen].oceansfx = copymapscr.oceansfx;
4788 screens[screen].bosssfx = copymapscr.bosssfx;
4789 screens[screen].secretsfx = copymapscr.secretsfx;
4790 screens[screen].holdupsfx = copymapscr.holdupsfx;
4791 screens[screen].flags = copymapscr.flags;
4792 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4793 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4794 screens[screen].flags3 = copymapscr.flags3;
4795 screens[screen].flags4 = copymapscr.flags4;
4796 screens[screen].flags5 = copymapscr.flags5;
4797 screens[screen].flags6 = copymapscr.flags6;
4798 screens[screen].flags7 = copymapscr.flags7;
4799 screens[screen].flags8 = copymapscr.flags8;
4800 screens[screen].flags9 = copymapscr.flags9;
4801 screens[screen].flags10 = copymapscr.flags10;
4802 screens[screen].flags11 = copymapscr.flags11;
4803 screens[screen].item = copymapscr.item;
4804 screens[screen].hasitem = copymapscr.hasitem;
4805 screens[screen].itemx = copymapscr.itemx;
4806 screens[screen].itemy = copymapscr.itemy;
4807 screens[screen].nextmap = copymapscr.nextmap;
4808 screens[screen].nextscr = copymapscr.nextscr;
4809 screens[screen].nocarry = copymapscr.nocarry;
4810 screens[screen].noreset = copymapscr.noreset;
4811 screens[screen].exstate_reset = copymapscr.exstate_reset;
4812 screens[screen].exstate_carry = copymapscr.exstate_carry;
4813 screens[screen].path[0] = copymapscr.path[0];
4814 screens[screen].path[1] = copymapscr.path[1];
4815 screens[screen].path[2] = copymapscr.path[2];
4816 screens[screen].path[3] = copymapscr.path[3];
4817 screens[screen].pattern = copymapscr.pattern;
4818 screens[screen].exitdir = copymapscr.exitdir;
4819 screens[screen].screen_midi = copymapscr.screen_midi;
4820 screens[screen].stairx = copymapscr.stairx;
4821 screens[screen].stairy = copymapscr.stairy;
4822 screens[screen].timedwarptics = copymapscr.timedwarptics;
4823 mark_save_dirty();
4824 }
4825 }
4826
4827 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4828 {
4829 if(can_paste)
4830 {
4831 screens[screen].warpreturnc = copymapscr.warpreturnc;
4832 screens[screen].warparrivalx = copymapscr.warparrivalx;
4833 screens[screen].warparrivaly = copymapscr.warparrivaly;
4834
4835 for(int32_t i=0; i<4; i++)
4836 {
4837 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4838 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4839 }
4840
4841 mark_save_dirty();
4842 }
4843 }
4844
4845 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4846 {
4847 if(can_paste)
4848 {
4849 for(int32_t i=0; i<4; i++)
4850 screens[screen].door[i] = copymapscr.door[i];
4851
4852 screens[screen].door_combo_set = copymapscr.door_combo_set;
4853 mark_save_dirty();
4854 }
4855 }
4856
4857 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4858 {
4859 if(can_paste)
4860 {
4861 for(int32_t i=0; i<6; i++)
4862 {
4863 screens[screen].layermap[i] = copymapscr.layermap[i];
4864 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4865 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4866 }
4867
4868 mark_save_dirty();
4869 }
4870 }
4871
4872 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4873 {
4874 if(can_paste)
4875 {
4876 screens[screen].room = copymapscr.room;
4877 screens[screen].catchall = copymapscr.catchall;
4878 mark_save_dirty();
4879 }
4880 }
4881
4882 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4883 {
4884 if(can_paste)
4885 {
4886 screens[screen].guy = copymapscr.guy;
4887 screens[screen].guytile = copymapscr.guytile;
4888 screens[screen].guycs = copymapscr.guycs;
4889 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4890 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4891 screens[screen].str = copymapscr.str;
4892 mark_save_dirty();
4893 }
4894 }
4895
4896 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4897 {
4898 if(can_paste)
4899 {
4900 screens[screen].color = copymapscr.color;
4901 screens[screen].valid|=mVALID;
4902 refresh_color();
4903
4904 mark_save_dirty();
4905 }
4906 }
4907
4908 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4909 {
4910 if(can_paste)
4911 {
4912 copy_mapscr(&screens[screen], &copymapscr);
4913 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4914 screens[screen].valid|=mVALID;
4915
4916 refresh_color();
4917
4918 mark_save_dirty();
4919 }
4920 }
4921
4922
4923 void zmap::PasteToAll(const mapscr& copymapscr)
4924 {
4925 if(can_paste)
4926 {
4927 for(int32_t x=0; x<128; x++)
4928 {
4929 if(!(screens[x].valid&mVALID))
4930 {
4931 screens[x].valid |= mVALID;
4932 screens[x].color = copymapscr.color;
4933 }
4934
4935 for(int32_t i=0; i<176; i++)
4936 {
4937 screens[x].data[i] = copymapscr.data[i];
4938 screens[x].cset[i] = copymapscr.cset[i];
4939 screens[x].sflag[i] = copymapscr.sflag[i];
4940 }
4941 }
4942
4943 refresh_color();
4944
4945 mark_save_dirty();
4946 }
4947 }
4948
4949 void zmap::PasteAllToAll(const mapscr& copymapscr)
4950 {
4951 if(can_paste)
4952 {
4953 for(int32_t x=0; x<128; x++)
4954 {
4955 copy_mapscr(&screens[x], &copymapscr);
4956 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4957 //screens[x]=copymapscr;
4958 }
4959
4960 refresh_color();
4961
4962 mark_save_dirty();
4963 }
4964 }
4965
4966 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4967 {
4968 if(can_paste)
4969 {
4970 for(int32_t i=0; i<10; i++)
4971 screens[screen].enemy[i]=copymapscr.enemy[i];
4972 }
4973 }
4974
4975 bool zmap::CanGoBack() const
4976 {
4977 return !cursor_undo_stack.empty();
4978 }
4979
4980 bool zmap::CanGoForward() const
4981 {
4982 return !cursor_redo_stack.empty();
4983 }
4984
4985 void zmap::GoBack()
4986 {
4987 if (!CanGoBack())
4988 return;
4989
4990 cursor_redo_stack.push(cursor);
4991
4992 ConfigureCursorHistory(false);
4993 setCursor(cursor_undo_stack.back());
4994 ConfigureCursorHistory(true);
4995
4996 cursor_undo_stack.pop_back();
4997 }
4998
4999 void zmap::GoForward()
5000 {
5001 if (!CanGoForward())
5002 return;
5003
5004 cursor_undo_stack.push_back(cursor);
5005
5006 ConfigureCursorHistory(false);
5007 setCursor(cursor_redo_stack.top());
5008 ConfigureCursorHistory(true);
5009
5010 cursor_redo_stack.pop();
5011 }
5012
5013 void zmap::CapCursorHistory()
5014 {
5015 int max_history_size = 1000;
5016 while (cursor_undo_stack.size() > max_history_size)
5017 cursor_undo_stack.pop_front();
5018 }
5019
5020 void zmap::ConfigureCursorHistory(bool enable)
5021 {
5022 cursor_history_enabled = enable;
5023 }
5024
5025 void zmap::setCopyFFC(int32_t n)
5026 {
5027 copyffc = n;
5028 }
5029
5030 void zmap::update_combo_cycling()
5031 {
5032 if(!prv_mode||!prv_cmbcycle)
5033 {
5034 return;
5035 }
5036
5037 int32_t x;
5038 int32_t newdata[176];
5039 int32_t newcset[176];
5040 bool restartanim[MAXCOMBOS] = {0};
5041
5042 for(int32_t i=0; i<176; i++)
5043 {
5044 newdata[i]=-1;
5045 newcset[i]=-1;
5046
5047 x=prvscr.data[i];
5048
5049 //time to restart
5050 if((combobuf[x].aclk>=combobuf[x].speed) &&
5051 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5052 combobuf[x].can_cycle())
5053 {
5054 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5055 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5056
5057 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5058 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5059 int32_t c = newdata[i];
5060
5061 if(combobuf[c].animflags & AF_CYCLE)
5062 {
5063 restartanim[c]=true;
5064 }
5065 }
5066 }
5067
5068 for(int32_t i=0; i<176; i++)
5069 {
5070 x=prvscr.data[i];
5071
5072 //time to restart
5073 if((combobuf[x].aclk>=combobuf[x].speed) &&
5074 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5075 combobuf[x].can_cycle())
5076 {
5077 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5078 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5079
5080 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5081 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5082 int32_t c = newdata[i];
5083
5084 if(combobuf[c].animflags & AF_CYCLE)
5085 {
5086 restartanim[c]=true;
5087 }
5088 }
5089 }
5090
5091 for(int32_t i=0; i<176; i++)
5092 {
5093 if(newdata[i]==-1)
5094 continue;
5095
5096 prvscr.data[i]=newdata[i];
5097 prvscr.cset[i]=newcset[i];
5098 }
5099
5100 word maxffc = prvscr.numFFC();
5101 for(word i=0; i<maxffc; i++)
5102 {
5103 ffcdata& ffc = prvscr.ffcs[i];
5104 newcombo const& cmb = combobuf[ffc.data];
5105
5106 //time to restart
5107 if((cmb.aclk>=cmb.speed) &&
5108 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5109 cmb.can_cycle())
5110 {
5111 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5112 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5113
5114 if(!(cmb.animflags & AF_CYCLENOCSET))
5115 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5116
5117 if(combobuf[ffc.data].animflags & AF_CYCLE)
5118 {
5119 restartanim[ffc.data]=true;
5120 }
5121 prvscr.ffcs[i].data = ffc.data;
5122 prvscr.ffcs[i].cset=ffc.cset;
5123 }
5124 }
5125
5126
5127 if(get_qr(qr_CMBCYCLELAYERS))
5128 {
5129 for(int32_t j=0; j<6; j++)
5130 {
5131 if(!prvlayers[j].valid)
5132 continue;
5133
5134 for(int32_t i=0; i<176; i++)
5135 {
5136 newdata[i]=-1;
5137 newcset[i]=-1;
5138
5139 x=(prvlayers[j]).data[i];
5140
5141 //time to restart
5142 if((combobuf[x].aclk>=combobuf[x].speed) &&
5143 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5144 combobuf[x].can_cycle())
5145 {
5146 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5147 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5148
5149 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5150 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5151 int32_t c = newdata[i];
5152
5153 if(combobuf[c].animflags & AF_CYCLE)
5154 {
5155 restartanim[c]=true;
5156 }
5157 }
5158 }
5159
5160 for(int32_t i=0; i<176; i++)
5161 {
5162 x=(prvlayers[j]).data[i];
5163
5164 //time to restart
5165 if((combobuf[x].aclk>=combobuf[x].speed) &&
5166 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5167 combobuf[x].can_cycle())
5168 {
5169 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5170 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5171
5172 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5173 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5174 int32_t c = newdata[i];
5175
5176 if(combobuf[c].animflags & AF_CYCLE)
5177 {
5178 restartanim[c]=true;
5179 }
5180 }
5181 }
5182
5183 for(int32_t i=0; i<176; i++)
5184 {
5185 if(newdata[i]==-1)
5186 continue;
5187
5188 prvlayers[j].data[i]=newdata[i];
5189 prvlayers[j].cset[i]=newcset[i];
5190 }
5191 }
5192 }
5193
5194 for(int32_t i=0; i<MAXCOMBOS; i++)
5195 {
5196 if(restartanim[i])
5197 {
5198 combobuf[i].tile = combobuf[i].o_tile;
5199 combobuf[i].cur_frame=0;
5200 combobuf[i].aclk = 0;
5201 }
5202 }
5203 }
5204
5205 void zmap::update_freeform_combos()
5206 {
5207 if(!prv_mode||!prv_cmbcycle)
5208 {
5209 return;
5210 }
5211
5212 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5213 word maxffc = prvscr.numFFC();
5214 for(int32_t i=0; i<maxffc; i++)
5215 {
5216 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5217 {
5218 for(int32_t j=0; j<maxffc; j++)
5219 {
5220 if(i!=j)
5221 {
5222 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5223 {
5224 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5225 {
5226 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5227 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5228 {
5229 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5230 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5231 if(prvscr.ffcs[j].flags&ffc_changethis)
5232 {
5233 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5234 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5235 }
5236
5237 if(prvscr.ffcs[j].flags&ffc_changenext)
5238 prvscr.ffcs[i].data += 1;
5239
5240 if(prvscr.ffcs[j].flags&ffc_changeprev)
5241 prvscr.ffcs[i].data -= 1;
5242
5243 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5244 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5245 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5246
5247 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5248 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5249 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5250 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5251
5252 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5253 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5254 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5255 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5256 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5257
5258 if(prvscr.ffcs[i].flags&ffc_carryover)
5259 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5260 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5261
5262 prvscr.ffcs[i].flags&=~ffc_changer;
5263 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5264 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5265
5266 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5267 {
5268 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5269 }
5270
5271 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5272 {
5273 int32_t k=0;
5274
5275 if(prvscr.ffcs[j].flags&ffc_swapnext)
5276 k=j<(MAXFFCS-1)?j+1:0;
5277
5278 if(prvscr.ffcs[j].flags&ffc_swapprev)
5279 k=j>0?j-1:(MAXFFCS-1);
5280
5281 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5282 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5283 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5284 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5285 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5286 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5287 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5288 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5289 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5290 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5291 }
5292 }
5293 }
5294 }
5295 }
5296 }
5297
5298 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5299 {
5300 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5301 {
5302 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5303 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5304 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5305 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5306 }
5307 else
5308 {
5309 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5310 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5311 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5312 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5313 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5314 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5315
5316 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5317 {
5318 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5319
5320 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5321
5322 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5323
5324 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5325 }
5326 }
5327 }
5328 else
5329 {
5330 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5331 prvscr.ffcs[i].delay--;
5332 }
5333
5334 if(prvscr.ffcs[i].x<-32)
5335 {
5336 if(prvscr.flags6&fWRAPAROUNDFF)
5337 {
5338 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5339 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5340 }
5341 else
5342 {
5343 prvscr.ffcs[i].data = 0;
5344 prvscr.ffcs[i].flags&=~ffc_carryover;
5345 }
5346 }
5347
5348 if(prvscr.ffcs[i].y<-32)
5349 {
5350 if(prvscr.flags6&fWRAPAROUNDFF)
5351 {
5352 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5353 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5354 }
5355 else
5356 {
5357 prvscr.ffcs[i].data = 0;
5358 prvscr.ffcs[i].flags&=~ffc_carryover;
5359 }
5360 }
5361
5362 if(prvscr.ffcs[i].x>=288)
5363 {
5364 if(prvscr.flags6&fWRAPAROUNDFF)
5365 {
5366 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5367 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5368 }
5369 else
5370 {
5371 prvscr.ffcs[i].data = 0;
5372 prvscr.ffcs[i].flags&=~ffc_carryover;
5373 }
5374 }
5375
5376 if(prvscr.ffcs[i].y>=208)
5377 {
5378 if(prvscr.flags6&fWRAPAROUNDFF)
5379 {
5380 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5381 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5382 }
5383 else
5384 {
5385 prvscr.ffcs[i].data = 0;
5386 prvscr.ffcs[i].flags&=~ffc_carryover;
5387 }
5388 }
5389
5390 }
5391 }
5392 }
5393
5394 void zmap::goto_dmapscr(int dmap, int scr)
5395 {
5396 goto_mapscr(DMaps[dmap].map, scr + DMaps[dmap].xoff);
5397 }
5398 void zmap::goto_mapscr(int map, int scr)
5399 {
5400 auto new_cursor = cursor;
5401 new_cursor.map = map;
5402 new_cursor.setScreen(scr);
5403 setCursor(std::move(new_cursor));
5404 }
5405
5406 void zmap::dowarp(int32_t type, int32_t index)
5407 {
5408 set_warpback();
5409 if(type==0)
5410 {
5411
5412 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5413 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5414
5415 switch(screens[cursor.screen].tilewarptype[index])
5416 {
5417 case wtCAVE:
5418 case wtNOWARP:
5419 break;
5420
5421 default:
5422 goto_dmapscr(dmap, scr);
5423 break;
5424 }
5425 }
5426 else if(type==1)
5427 {
5428 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5429 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5430
5431 switch(screens[cursor.screen].sidewarptype[index])
5432 {
5433 case wtCAVE:
5434 case wtNOWARP:
5435 break;
5436
5437 default:
5438 goto_dmapscr(dmap, scr);
5439 break;
5440 }
5441 }
5442 }
5443
5444 extern int32_t prv_twon;
5445
5446 void zmap::prv_dowarp(int32_t type, int32_t index)
5447 {
5448 if(type==0)
5449 {
5450
5451 int32_t dmap=prvscr.tilewarpdmap[index];
5452 int32_t scr=prvscr.tilewarpscr[index];
5453
5454 switch(prvscr.tilewarptype[index])
5455 {
5456 case wtCAVE:
5457 case wtNOWARP:
5458 break;
5459
5460 default:
5461 //setCurrMap(DMaps[dmap].map);
5462 //setCurrScr(scr+DMaps[dmap].xoff);
5463 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5464 refresh_color();
5465 //prv_cmbcycle=0;
5466 break;
5467 }
5468 }
5469 else if(type==1)
5470 {
5471 int32_t dmap=prvscr.sidewarpdmap[index];
5472 int32_t scr=prvscr.sidewarpscr[index];
5473
5474 switch(prvscr.sidewarptype[index])
5475 {
5476 case wtCAVE:
5477 case wtNOWARP:
5478 break;
5479
5480 default:
5481 //setCurrMap(DMaps[dmap].map);
5482 //setCurrScr(scr+DMaps[dmap].xoff);
5483 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5484 refresh_color();
5485 //prv_cmbcycle=0;
5486 break;
5487 }
5488 }
5489
5490 if(prv_twon)
5491 {
5492 prv_time=get_prvscr()->timedwarptics;
5493 }
5494 }
5495
5496 void zmap::dowarp2(int32_t ring,int32_t index)
5497 {
5498 set_warpback();
5499 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5500 }
5501
5502 void zmap::set_warpback()
5503 {
5504 warpbackmap = cursor.map;
5505 warpbackscreen = cursor.screen;
5506 }
5507 bool zmap::has_warpback()
5508 {
5509 return warpbackmap && warpbackscreen
5510 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5511 }
5512 void zmap::warpback()
5513 {
5514 if(!has_warpback())
5515 return;
5516
5517 int m = cursor.map, s = cursor.screen;
5518 goto_mapscr(*warpbackmap, *warpbackscreen);
5519 warpbackmap = m;
5520 warpbackscreen = s;
5521 }
5522
5523 bool save_msgstrs(const char *path)
5524 {
5525 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5526
5527 if(!f)
5528 {
5529 return false;
5530 }
5531
5532 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5533 {
5534 pack_fclose(f);
5535 return true;
5536 }
5537
5538 pack_fclose(f);
5539 return false;
5540 }
5541
5542 1 bool save_strings_tsv(const char *path)
5543 {
5544 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5545
5546
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5547 {
5548 return false;
5549 }
5550
5551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5552 {
5553 1 pack_fclose(f);
5554 1 return true;
5555 }
5556
5557 pack_fclose(f);
5558 return false;
5559 1 }
5560
5561 bool save_msgstrs_text(const char *path)
5562 {
5563 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5564
5565 if(!f)
5566 {
5567 return false;
5568 }
5569
5570 if(writestrings_text(f)==0)
5571 {
5572 pack_fclose(f);
5573 return true;
5574 }
5575
5576 pack_fclose(f);
5577 return false;
5578 }
5579
5580 bool load_msgstrs(const char *path, int32_t startstring)
5581 {
5582 //these are here to bypass compiler warnings about unused arguments
5583 startstring=startstring;
5584
5585 dword section_id;
5586 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5587
5588 if(!f)
5589 {
5590 return false;
5591 }
5592
5593 if(!p_mgetl(&section_id,f))
5594 {
5595 return false;
5596 }
5597
5598 if(section_id==ID_STRINGS)
5599 {
5600 if(readstrings(f, &header)==0)
5601 {
5602 pack_fclose(f);
5603 return true;
5604 }
5605 else
5606 {
5607 pack_fclose(f);
5608 return false;
5609 }
5610 }
5611
5612 pack_fclose(f);
5613 return false;
5614 }
5615
5616 bool load_strings_tsv(const char *path)
5617 {
5618 try
5619 {
5620 parse_strings_tsv(util::read_text_file(path));
5621 }
5622 catch (std::exception& ex)
5623 {
5624 InfoDialog("Import .tsv Error", ex.what()).show();
5625 return false;
5626 }
5627 return true;
5628 }
5629
5630 bool save_pals(const char *path)
5631 {
5632 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5633
5634 if(!f)
5635 {
5636 return false;
5637 }
5638
5639 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5640 {
5641 pack_fclose(f);
5642 return true;
5643 }
5644
5645 pack_fclose(f);
5646 return false;
5647 }
5648
5649 bool load_pals(const char *path, int32_t startcset)
5650 {
5651 dword section_id;
5652 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5653
5654 if(!f)
5655 {
5656 return false;
5657 }
5658
5659 if(!p_mgetl(&section_id,f))
5660 {
5661 return false;
5662 }
5663
5664 if(section_id==ID_CSETS)
5665 {
5666 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5667 {
5668 pack_fclose(f);
5669 loadlvlpal(Color);
5670 return true;
5671 }
5672 else
5673 {
5674 pack_fclose(f);
5675 return false;
5676 }
5677 }
5678
5679 return false;
5680 }
5681
5682 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5683 bool save_guys(const char *path)
5684 {
5685 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5686
5687 if(!f)
5688 {
5689 return false;
5690 }
5691
5692 /*
5693 int32_t id = ID_GUYS;
5694 if(!p_mputl(id,f))
5695 {
5696 return false;
5697 }
5698 */
5699
5700 zquestheader h;
5701 h.zelda_version = 0x250;
5702 h.build = 21;
5703
5704 if(writeguys(f, &h)==0)
5705 {
5706 pack_fclose(f);
5707 return true;
5708 }
5709
5710 pack_fclose(f);
5711 return false;
5712 }
5713
5714 bool load_guys(const char *path)
5715 {
5716 dword section_id;
5717 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5718
5719 if(!f)
5720 {
5721 return false;
5722 }
5723
5724 if(!p_mgetl(&section_id,f))
5725 {
5726 pack_fclose(f);
5727 return false;
5728 }
5729
5730 zquestheader h;
5731 h.zelda_version = 0x250;
5732 h.build = 21;
5733
5734 if(section_id==ID_GUYS)
5735 {
5736 if(readguys(f, &h)==0)
5737 {
5738 pack_fclose(f);
5739 return true;
5740 }
5741 }
5742
5743 pack_fclose(f);
5744 return false;
5745 }
5746
5747
5748 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5749 bool save_combo_alias(const char *path)
5750 {
5751 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5752
5753 if(!f)
5754 {
5755 return false;
5756 }
5757
5758 zquestheader h;
5759 h.zelda_version = 0x250;
5760 h.build = 21;
5761
5762 if(writecomboaliases(f, 0, 0)==0)
5763 {
5764 pack_fclose(f);
5765 return true;
5766 }
5767
5768 pack_fclose(f);
5769 return false;
5770 }
5771
5772 bool load_combo_alias(const char *path)
5773 {
5774 dword section_id;
5775 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5776
5777 if(!f)
5778 {
5779 return false;
5780 }
5781
5782 if(!p_mgetl(&section_id,f))
5783 {
5784 pack_fclose(f);
5785 return false;
5786 }
5787
5788 zquestheader h;
5789 h.zelda_version = 0x250;
5790 h.build = 21;
5791
5792 if(section_id==ID_COMBOALIASES)
5793 {
5794 if(readcomboaliases(f, &h, 0, 0)==0)
5795 {
5796 pack_fclose(f);
5797 return true;
5798 }
5799 }
5800
5801 pack_fclose(f);
5802 return false;
5803 }
5804
5805 bool load_zgp(const char *path)
5806 {
5807 dword section_id;
5808 word section_version;
5809 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5810
5811 if(!f)
5812 return false;
5813
5814 if(!p_mgetl(&section_id,f))
5815 {
5816 pack_fclose(f);
5817 return false;
5818 }
5819
5820 if(section_id!=ID_GRAPHICSPACK)
5821 {
5822 pack_fclose(f);
5823 return false;
5824 }
5825
5826 //section version info
5827 if(!p_igetw(&section_version,f))
5828 {
5829 return 2;
5830 }
5831
5832 if(!read_deprecated_section_cversion(f))
5833 {
5834 return 3;
5835 }
5836
5837 //tiles
5838 if(!p_mgetl(&section_id,f))
5839 {
5840 pack_fclose(f);
5841 return false;
5842 }
5843
5844 if(section_id==ID_TILES)
5845 {
5846 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5847 {
5848 pack_fclose(f);
5849 init_tiles(true, &header);
5850 return false;
5851 }
5852 }
5853 else
5854 {
5855 pack_fclose(f);
5856 return false;
5857 }
5858
5859 //combos
5860 if(!p_mgetl(&section_id,f))
5861 {
5862 pack_fclose(f);
5863 return false;
5864 }
5865
5866 if(section_id==ID_COMBOS)
5867 {
5868 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5869 {
5870 pack_fclose(f);
5871 return false;
5872 }
5873 }
5874 else
5875 {
5876 pack_fclose(f);
5877 return false;
5878 }
5879
5880 //palettes
5881 if(!p_mgetl(&section_id,f))
5882 {
5883 pack_fclose(f);
5884 return false;
5885 }
5886
5887 if(section_id==ID_CSETS)
5888 {
5889 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5890 {
5891 pack_fclose(f);
5892 return false;
5893 }
5894 }
5895 else
5896 {
5897 pack_fclose(f);
5898 return false;
5899 }
5900
5901 //items
5902 if(!p_mgetl(&section_id,f))
5903 {
5904 pack_fclose(f);
5905 return false;
5906 }
5907
5908 if(section_id==ID_ITEMS)
5909 {
5910 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5911 {
5912 pack_fclose(f);
5913 return false;
5914 }
5915 }
5916 else
5917 {
5918 pack_fclose(f);
5919 return false;
5920 }
5921
5922 //weapons
5923 if(!p_mgetl(&section_id,f))
5924 {
5925 pack_fclose(f);
5926 return false;
5927 }
5928
5929 if(section_id==ID_WEAPONS)
5930 {
5931 if(readweapons(f, &header)!=0)
5932 {
5933 pack_fclose(f);
5934 return false;
5935 }
5936 }
5937 else
5938 {
5939 pack_fclose(f);
5940 return false;
5941 }
5942
5943 //read the triforce pieces info and make sure it worked
5944 //really do this?
5945
5946 //read the game icons info and make sure it worked
5947 if(!p_mgetl(&section_id,f))
5948 {
5949 pack_fclose(f);
5950 return false;
5951 }
5952
5953 if(section_id==ID_ICONS)
5954 {
5955 if(readgameicons(f, &header, &QMisc)!=0)
5956 {
5957 pack_fclose(f);
5958 return false;
5959 }
5960 }
5961 else
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966
5967 //read the misc colors info and map styles info and make sure it worked
5968 if(!p_mgetl(&section_id,f))
5969 {
5970 pack_fclose(f);
5971 return false;
5972 }
5973
5974 if(section_id==ID_COLORS)
5975 {
5976 if(readmisccolors(f, &header, &QMisc)!=0)
5977 {
5978 pack_fclose(f);
5979 return false;
5980 }
5981 }
5982 else
5983 {
5984 pack_fclose(f);
5985 return false;
5986 }
5987
5988 //read the door combo sets and make sure it worked
5989 if(!p_mgetl(&section_id,f))
5990 {
5991 pack_fclose(f);
5992 return false;
5993 }
5994
5995 if(section_id==ID_DOORS)
5996 {
5997 if(readdoorcombosets(f, &header)!=0)
5998 {
5999 pack_fclose(f);
6000 return false;
6001 }
6002 }
6003 else
6004 {
6005 pack_fclose(f);
6006 return false;
6007 }
6008
6009 //read the template screens and make sure it worked
6010 //really do this?
6011
6012 //yay! it worked! close the file and say everything was ok.
6013 loadlvlpal(Color);
6014 setup_combo_animations();
6015 setup_combo_animations2();
6016 pack_fclose(f);
6017 return true;
6018 }
6019
6020 bool save_zgp(const char *path)
6021 {
6022 reset_combo_animations();
6023 reset_combo_animations2();
6024
6025 //open the file
6026 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6027
6028 if(!f)
6029 return false;
6030
6031 dword section_id=ID_GRAPHICSPACK;
6032 dword section_version=V_GRAPHICSPACK;
6033
6034 //section id
6035 if(!p_mputl(section_id,f))
6036 {
6037 return 1;
6038 }
6039
6040 //section version info
6041 if(!p_iputw(section_version,f))
6042 {
6043 return 2;
6044 }
6045
6046 if(!write_deprecated_section_cversion(section_version,f))
6047 {
6048 return 3;
6049 }
6050
6051 //tiles
6052 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6053 {
6054 pack_fclose(f);
6055 return false;
6056 }
6057
6058 //combos
6059 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6060 {
6061 pack_fclose(f);
6062 return false;
6063 }
6064
6065 //palettes
6066 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6067 {
6068 pack_fclose(f);
6069 return false;
6070 }
6071
6072 //items
6073 if(writeitems(f, &header)!=0)
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 //weapons
6080 if(writeweapons(f, &header)!=0)
6081 {
6082 pack_fclose(f);
6083 return false;
6084 }
6085
6086 //write the triforce pieces info and make sure it worked
6087 //really do this?
6088
6089 //write the game icons info and make sure it worked
6090 if(writegameicons(f, &header)!=0)
6091 {
6092 pack_fclose(f);
6093 return false;
6094 }
6095
6096 //write the misc colors info and map styles info and make sure it worked
6097 if(writemisccolors(f, &header)!=0)
6098 {
6099 pack_fclose(f);
6100 return false;
6101 }
6102
6103 //write the door combo sets and make sure it worked
6104 if(writedoorcombosets(f, &header)!=0)
6105 {
6106 pack_fclose(f);
6107 return false;
6108 }
6109
6110 //write the template screens and make sure it worked
6111 //really do this?
6112
6113 pack_fclose(f);
6114 return true;
6115 }
6116
6117 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6118 {
6119 //open the file
6120 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6121
6122 if(!f)
6123 return false;
6124
6125 dword section_id=ID_SUBSCREEN;
6126 dword s_version=V_SUBSCREEN;
6127
6128 if(!p_mputl(section_id,f))
6129 {
6130 pack_fclose(f);
6131 return false;
6132 }
6133
6134 if(!p_iputw(s_version,f))
6135 {
6136 pack_fclose(f);
6137 return false;
6138 }
6139
6140 if(!write_deprecated_section_cversion(s_version,f))
6141 {
6142 pack_fclose(f);
6143 return false;
6144 }
6145
6146 if(savefrom.write(f))
6147 {
6148 pack_fclose(f);
6149 return false;
6150 }
6151
6152 pack_fclose(f);
6153 return true;
6154 }
6155
6156 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6157 {
6158 //open the file
6159 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6160
6161 if(!f)
6162 return false;
6163
6164 dword section_id;
6165 dword s_version;
6166
6167 if(!p_mgetl(&section_id,f))
6168 {
6169 pack_fclose(f);
6170 return false;
6171 }
6172
6173 if(section_id!=ID_SUBSCREEN)
6174 {
6175 pack_fclose(f);
6176 return false;
6177 }
6178
6179 if(!p_igetw(&s_version,f))
6180 {
6181 pack_fclose(f);
6182 return false;
6183 }
6184
6185 if (s_version > V_SUBSCREEN)
6186 return qe_version;
6187
6188 if(!read_deprecated_section_cversion(f))
6189 {
6190 pack_fclose(f);
6191 return false;
6192 }
6193
6194 if(s_version < 8)
6195 {
6196 subscreen_group g;
6197 memset(&g,0,sizeof(subscreen_group));
6198 if(read_one_old_subscreen(f,&g,s_version)!=0)
6199 {
6200 pack_fclose(f);
6201 return false;
6202 }
6203 if(g.ss_type != loadto.sub_type)
6204 {
6205 pack_fclose(f);
6206 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6207 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6208 return false;
6209 }
6210 loadto.clear();
6211 if(g.objects[0].type != ssoNULL)
6212 loadto.load_old(g);
6213 }
6214 else
6215 {
6216 ZCSubscreen tmp = ZCSubscreen();
6217 if (tmp.read(f, s_version))
6218 {
6219 pack_fclose(f);
6220 return false;
6221 }
6222 if(tmp.sub_type != loadto.sub_type)
6223 {
6224 pack_fclose(f);
6225 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6226 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6227 return false;
6228 }
6229 loadto.clear();
6230 loadto = tmp;
6231 }
6232
6233 pack_fclose(f);
6234 return true;
6235 }
6236
6237 bool setMapCount2(int32_t c)
6238 {
6239 int32_t oldmapcount=map_count;
6240 int32_t cur_map=Map.getCurrMap();
6241
6242 bound(c,1,MAXMAPS);
6243 map_count=c;
6244
6245 try
6246 {
6247 TheMaps.resize(c*MAPSCRS);
6248 Map.force_refr_pointer();
6249 map_infos.resize(c);
6250 }
6251 catch(...)
6252 {
6253 displayinfo("Error","Failed to change map count.");
6254 return false;
6255 }
6256
6257 bound(cur_map,0,c-1);
6258 if(map_count>oldmapcount)
6259 {
6260 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6261 {
6262 // copy the default palette to the new maps
6263 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6264
6265 Map.setCurrMap(mc);
6266 for(int32_t ms=0; ms<MAPSCRS; ms++)
6267 Map.clearscr(ms);
6268 }
6269 Map.setCurrMap(cur_map);
6270 }
6271 else
6272 {
6273 Map.setCurrMap(cur_map);
6274 if(!layers_valid(Map.CurrScr()))
6275 fix_layers(Map.CurrScr(), false);
6276
6277 for(int32_t i=0; i<MAXDMAPS; i++)
6278 {
6279 if(DMaps[i].map>=map_count)
6280 {
6281 DMaps[i].map=map_count-1;
6282 }
6283 }
6284 }
6285
6286 return true;
6287 }
6288
6289 extern BITMAP *bmap;
6290
6291 static bool loading_file_new = false;
6292 int32_t init_quest(std::string tileset_path)
6293 {
6294 if (tileset_path.empty())
6295 tileset_path = DEFAULT_TILESET;
6296
6297 loading_file_new = true;
6298 load_quest(tileset_path.c_str());
6299 loading_file_new = false;
6300
6301 set_window_title("ZC Editor - Untitled Quest");
6302 zinit.last_map = 0;
6303 zinit.last_screen = 0;
6304
6305 if(bmap != NULL)
6306 {
6307 destroy_bitmap(bmap);
6308 bmap=NULL;
6309 }
6310
6311 return 0;
6312 }
6313
6314 void set_questpwd(std::string_view pwd, bool use_keyfile)
6315 {
6316 header.use_keyfile=use_keyfile;
6317
6318 // string_view actually has some quirks that make it less than ideal here.
6319 // It'd probably be best to replace it, but this works for now.
6320 memset(header.password, 0, 256);
6321 strcpy(header.password, pwd.data());
6322 header.dirty_password=true;
6323
6324 cvs_MD5Context ctx;
6325 cvs_MD5Init(&ctx);
6326 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6327 cvs_MD5Final(header.pwd_hash, &ctx);
6328 }
6329
6330
6331 bool is_null_pwd_hash(uint8_t *pwd_hash)
6332 {
6333 cvs_MD5Context ctx;
6334 uint8_t md5sum[16];
6335 char pwd[2]="";
6336
6337 cvs_MD5Init(&ctx);
6338 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6339 cvs_MD5Final(md5sum, &ctx);
6340
6341 return (memcmp(md5sum,pwd_hash,16)==0);
6342 }
6343
6344 static DIALOG pwd_dlg[] =
6345 {
6346 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6347 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6348 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6349 // 2 (filename)
6350 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6351 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6352 // 4 (challenge hash)
6353 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6354 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6355 // 6 (password)
6356 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6357 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6358 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6359 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6360 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6361 };
6362
6363 int32_t reverse_string(char* str)
6364 {
6365
6366 if(NULL==str)
6367 {
6368 return -1; //no string
6369 }
6370
6371 int32_t l=(int32_t)strlen(str)-1; //get the string length
6372
6373 if(1==l)
6374 {
6375 return 1;
6376 }
6377
6378 char c;
6379
6380 for(int32_t x=0; x < l; x++,l--)
6381 {
6382 c = str[x];
6383 str[x] = str[l];
6384 str[l] = c;
6385 }
6386
6387 return 0;
6388 }
6389
6390 #ifdef __GNUC__
6391 #pragma GCC diagnostic push
6392 #pragma GCC diagnostic ignored "-Wunreachable-code"
6393 #endif
6394
6395 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6396 {
6397
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6398 11 return 1;
6399
6400 #ifdef __EMSCRIPTEN__
6401 return 1;
6402 #endif
6403
6404 //Protection against compiling a release version with password protection off.
6405 static bool passguard = false;
6406
6407 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6408 #define MUST_HAVE_PASSWORD
6409 passguard = true;
6410 #endif
6411
6412 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6413 #if (defined _MSC_VER || defined _NPASS)
6414 return 1;
6415 #endif
6416 #endif
6417 if(devpwd()) return 1;
6418
6419 char hash_string[33];
6420
6421 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6422 {
6423 return 1;
6424 }
6425
6426 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6427 return true;
6428
6429 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6430 pwd_dlg[2].dp=get_filename(filename);
6431 cvs_MD5Context ctx;
6432 uint8_t md5sum[16]={0};
6433 char response[33]="";
6434 char prompt[256]="";
6435
6436 memcpy(md5sum, hdr->pwd_hash, 16);
6437
6438 for(int32_t i=0; i<300; ++i)
6439 {
6440 for(int32_t j=0; j<16; ++j)
6441 {
6442 sprintf(response+j*2, "%02x", md5sum[j]);
6443 }
6444
6445 if(i&1)
6446 {
6447 reverse_string(response);
6448 }
6449
6450 if(i==149)
6451 {
6452 strcpy(hash_string, response);
6453 }
6454
6455 cvs_MD5Init(&ctx);
6456 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6457 cvs_MD5Final(md5sum, &ctx);
6458 }
6459
6460 pwd_dlg[4].dp=hash_string;
6461
6462 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6463 {
6464 sprintf(prompt,"%s",response);
6465 }
6466
6467 pwd_dlg[6].dp=prompt;
6468
6469 large_dialog(pwd_dlg);
6470
6471 int32_t cancel = do_zqdialog(pwd_dlg,6);
6472
6473 if(cancel == 8)
6474 return 2;
6475
6476 bool ret=check_questpwd(hdr, prompt);
6477
6478 if(!ret)
6479 {
6480 ret=(strcmp(response,prompt)==0);
6481 }
6482 return ret ? 1 : 0;
6483 11 }
6484
6485 void set_rules(byte* newrules);
6486 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6487 {
6488 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6489
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6490 {
6491
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
22 auto [ret, dsa] = alert_confirm_dsa("Apply New Bugfixes",
6492
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6493 "\nWould you like to apply them?"
6494 "\n(Applies 'Bugfix' rule template, un-checking compat rules)");
6495
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(ret)
6496 {
6497 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6498 }
6499
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(dsa)
6500 {
6501 zc_set_config("zquest",cfg,1);
6502 }
6503 11 }
6504 11 }
6505
6506 #ifdef __GNUC__
6507 #pragma GCC diagnostic pop
6508 #endif
6509
6510 11 int32_t load_quest(const char *filename, bool show_progress)
6511 {
6512 11 zq_freeze_all_rti();
6513
6514 char buf[2048];
6515 byte skip_flags[4];
6516
6517 11 dword tileset_flags = 0;
6518
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6519 {
6520 44 skip_flags[i]=0;
6521 44 }
6522
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6523 7634 set_qr(i,0);
6524 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6525
6526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6527 {
6528 init_quest(DEFAULT_TILESET);
6529 }
6530 else
6531 {
6532 11 int32_t accessret = quest_access(filename, &header);
6533
6534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6535 {
6536 init_quest(DEFAULT_TILESET);
6537
6538 if(accessret == 0)
6539 ret=qe_pwd;
6540 else
6541 ret=qe_cancel;
6542 }
6543 else
6544 {
6545 11 Map.clear();
6546
6547
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6548
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6549
6550
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6551
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6552 11 .screen = zinit.last_screen,
6553 11 .viewscr = zinit.last_screen,
6554 11 .size = view_size,
6555 });
6556
6557 extern int32_t current_mappage;
6558 11 current_mappage = 0;
6559 11 bool found_default = false;
6560
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6561 {
6562 83 auto &pg = map_page[q];
6563
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6564 {
6565 2 current_mappage = q;
6566 2 break;
6567 }
6568
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6569 72 continue;
6570 else
6571 {
6572 9 current_mappage = q;
6573 9 found_default = true;
6574 }
6575 9 }
6576
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6577
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6578
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6579 11 saved = true;
6580
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6581
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6582
6583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6584 {
6585 destroy_bitmap(bmap);
6586 bmap=NULL;
6587 }
6588
6589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6590 {
6591 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6592 set_window_title(buf);
6593 }
6594 11 }
6595 }
6596
6597 11 Map.ClearCommandHistory();
6598
6599
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6600 {
6601 void load_size_poses();
6602 load_size_poses();
6603 }
6604
6605 11 return ret;
6606 }
6607
6608 int32_t load_tileset(const char *filename, dword tsetflags)
6609 {
6610 zq_freeze_all_rti();
6611
6612 byte skip_flags[4];
6613
6614 for(int32_t i=0; i<4; ++i)
6615 skip_flags[i]=0;
6616 for(int32_t i=0; i<qr_MAX; i++)
6617 set_qr(i,0);
6618 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6619
6620 if(ret!=qe_OK)
6621 init_quest(DEFAULT_TILESET);
6622 else
6623 {
6624 if(tsetflags & TILESET_BUGFIX)
6625 applyRuleTemplate(ruletemplateFixCompat);
6626 if(tsetflags & TILESET_SCR_BUGFIX)
6627 applyRuleTemplate(ruletemplateFixZSCompat);
6628
6629 int32_t accessret = quest_access(filename, &header);
6630
6631 if(accessret != 1)
6632 {
6633 init_quest(DEFAULT_TILESET);
6634
6635 if(accessret == 0)
6636 ret=qe_pwd;
6637 else
6638 ret=qe_cancel;
6639 }
6640 else
6641 {
6642 Map.clear();
6643 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6644 Map.setCurrScr(zinit.last_screen);
6645 extern int32_t current_mappage;
6646 current_mappage = 0;
6647 bool found_default = false;
6648 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6649 {
6650 auto &pg = map_page[q];
6651 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6652 {
6653 current_mappage = q;
6654 break;
6655 }
6656 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6657 continue;
6658 else
6659 {
6660 current_mappage = q;
6661 found_default = true;
6662 }
6663 }
6664 refresh(rALL);
6665 refresh_pal();
6666 set_rules(quest_rules);
6667
6668 if(bmap != NULL)
6669 {
6670 destroy_bitmap(bmap);
6671 bmap=NULL;
6672 }
6673
6674 set_window_title("ZC Editor - Untitled Quest");
6675 first_save = false;
6676 mark_save_dirty();
6677 memset(filepath,0,255);
6678 memset(temppath,0,255);
6679 }
6680 }
6681
6682 Map.ClearCommandHistory();
6683
6684 return ret;
6685 }
6686
6687 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6688 {
6689
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6690 new_return(1);
6691
6692
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6693 new_return(2);
6694
6695
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6696 new_return(3);
6697
6698
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6699 new_return(4);
6700
6701
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6702 {
6703
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6704 new_return(5);
6705
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6706 new_return(6);
6707 1363650 }
6708
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6709 new_return(7);
6710
6711
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6712 new_return(8);
6713
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6714 new_return(9);
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6716 new_return(10);
6717
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6718 new_return(11);
6719
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6720 new_return(12);
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6722 new_return(13);
6723
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6724 new_return(14);
6725
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6726 new_return(15);
6727
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6728 new_return(16);
6729
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6730 new_return(17);
6731
6732
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6733 new_return(18);
6734
6735
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6736 new_return(19);
6737
6738
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6739 new_return(20);
6740
6741
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6742 new_return(21);
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6744 new_return(22);
6745
6746
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6747 new_return(23);
6748
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6749 new_return(24);
6750
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6751 new_return(25);
6752
6753
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6754 new_return(26);
6755
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6756
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6757 new_return(27);
6758
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6759 new_return(28);
6760 272730 return 0;
6761 }
6762
6763 130 bool write_midi(MIDI *m,PACKFILE *f)
6764 {
6765 int32_t c;
6766
6767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6768
6769
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6770 {
6771
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6772
6773
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6774 {
6775
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6776 return false;
6777 1264 }
6778 4160 }
6779
6780 130 return true;
6781 130 }
6782
6783 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6784 {
6785 9 dword section_id=ID_HEADER;
6786 9 dword section_version=V_HEADER;
6787 9 dword section_size=0;
6788
6789 //file header string
6790
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6791 {
6792 new_return(1);
6793 }
6794
6795 //section id
6796
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6797 {
6798 new_return(2);
6799 }
6800
6801 //section version info
6802
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6803 {
6804 new_return(3);
6805 }
6806
6807
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
6808 {
6809 new_return(4);
6810 }
6811
6812
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6813 {
6814 18 fake_pack_writing=(writecycle==0);
6815
6816 //section size
6817
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6818 {
6819 new_return(5);
6820 }
6821
6822 18 writesize=0;
6823
6824 //finally... section data
6825
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6826 {
6827 new_return(6);
6828 }
6829
6830
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6831 {
6832 new_return(7);
6833 }
6834
6835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6836 {
6837 new_return(8);
6838 }
6839
6840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(Header->internal,f))
6841 {
6842 new_return(10);
6843 }
6844
6845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->quest_number,f))
6846 {
6847 new_return(11);
6848 }
6849
6850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->version,16,f))
6851 {
6852 new_return(12);
6853 }
6854
6855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->minver,16,f))
6856 {
6857 new_return(13);
6858 }
6859
6860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6861 {
6862 new_return(14);
6863 }
6864
6865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6866 {
6867 new_return(15);
6868 }
6869
6870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->use_keyfile,f))
6871 {
6872 new_return(16);
6873 }
6874
6875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6876 {
6877 new_return(17);
6878 }
6879
6880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6881 {
6882 new_return(19);
6883 }
6884
6885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(0,f)) //why are we doing this?
6886 //this is for map count, it seems. -Z
6887 {
6888 new_return(20);
6889 }
6890
6891 18 auto version = getVersion();
6892
6893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.major,f))
6894 {
6895 new_return(21);
6896 }
6897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.minor,f))
6898 {
6899 new_return(22);
6900 }
6901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.patch,f))
6902 {
6903 new_return(23);
6904 }
6905 // Fourth component is deprecated.
6906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6907 {
6908 new_return(24);
6909 }
6910
6911 // Numerous prerelease stages is deprecated.
6912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6913 {
6914 new_return(25);
6915 }
6916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6917 {
6918 new_return(26);
6919 }
6920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6921 {
6922 new_return(27);
6923 }
6924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6925 {
6926 new_return(28);
6927 }
6928
6929
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6930 {
6931 new_return(29);
6932 }
6933
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6934 {
6935 new_return(30);
6936 }
6937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6938 {
6939 new_return(31);
6940 }
6941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6942 {
6943 new_return(32);
6944 }
6945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6946 {
6947 new_return(33);
6948 }
6949
6950 // This is no longer set to anything.
6951 const char* tempsig[256];
6952 18 memset(tempsig, 0, 256);
6953
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6954 {
6955 new_return(34);
6956 }
6957
6958 char tempcompilersig[256];
6959 18 memset(tempcompilersig, 0, 256);
6960 18 strcpy(tempcompilersig, COMPILER_NAME);
6961
6962
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6963 {
6964 new_return(35);
6965 }
6966
6967 char tempcompilerversion[256];
6968 18 memset(tempcompilerversion, 0, 256);
6969 #ifdef _MSC_VER
6970 zc_itoa(_MSC_VER,tempcompilerversion,10);
6971 #else
6972 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6973 #endif
6974
6975
6976
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6977 {
6978 new_return(36);
6979 }
6980
6981
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6982 {
6983 new_return(37);
6984 }
6985
6986 // V_ZC_COMPILERSIG - a deprecated version field.
6987
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6988 {
6989 new_return(38);
6990 }
6991 #ifdef _MSC_VER
6992 if(!p_iputl((_MSC_VER / 100),f))
6993 {
6994 new_return(39);
6995 }
6996 #else
6997
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
6998 {
6999 new_return(39);
7000 }
7001 #endif
7002
7003
7004
7005 #ifdef _MSC_VER
7006 if(!p_iputl((_MSC_VER % 100),f))
7007 {
7008 new_return(41);
7009 }
7010 #else
7011
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7012 {
7013 new_return(41);
7014 }
7015 #endif
7016
7017 #ifdef _MSC_VER
7018 # if _MSC_VER >= 1400
7019 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7020 {
7021 new_return(40);
7022 }
7023 # else
7024 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7025 {
7026 new_return(40);
7027 }
7028 #endif
7029 #else
7030
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7031 {
7032 new_return(40);
7033 }
7034 #endif
7035
7036 #ifdef _MSC_VER
7037 if(!p_iputl((_MSC_BUILD),f))
7038 {
7039 new_return(42);
7040 }
7041 #else
7042
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7043 {
7044 new_return(42);
7045 }
7046 #endif
7047
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7048 {
7049 new_return(43);
7050 }
7051
7052 // Modules were removed (replaced by zinfo).
7053 char tempmodulename[1024];
7054 18 memset(tempmodulename, 0, 1024);
7055
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7056 {
7057 new_return(44);
7058 }
7059
7060 char tempdate[256];
7061 18 memset(tempdate, 0, 256);
7062 18 strcpy(tempdate, __DATE__);
7063
7064
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7065 {
7066 new_return(45);
7067 }
7068 char temptime[256];
7069 18 memset(temptime, 0, 256);
7070 18 strcpy(temptime, __TIME__);
7071
7072
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7073 {
7074 new_return(46);
7075 }
7076
7077
7078 char temptimezone[6];
7079 18 memset(temptimezone, 0, 6);
7080 18 strcpy(temptimezone, __TIMEZONE__);
7081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7082 {
7083 new_return(47);
7084 }
7085
7086
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7087 {
7088 new_return(48);
7089 }
7090
7091
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7092 {
7093 new_return(49);
7094 }
7095
7096
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7097 {
7098 new_return(50);
7099 }
7100
7101
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7102 {
7103 9 section_size=writesize;
7104 9 }
7105 18 }
7106
7107
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7108 {
7109 displayinfo("Error: writeheader()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7110 }
7111
7112 9 new_return(0);
7113 }
7114
7115 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7116 {
7117 //these are here to bypass compiler warnings about unused arguments
7118 9 Header=Header;
7119
7120 9 dword section_id=ID_RULES;
7121 9 dword section_version=V_RULES;
7122 9 dword section_size=0;
7123
7124 //section id
7125
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7126 {
7127 new_return(1);
7128 }
7129
7130 //section version info
7131
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7132 {
7133 new_return(2);
7134 }
7135
7136
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7137 {
7138 new_return(3);
7139 }
7140
7141
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputl(V_COMPATRULE,f))
7142 {
7143 new_return(6);
7144 }
7145
7146
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7147 {
7148 18 fake_pack_writing=(writecycle==0);
7149
7150 //section size
7151
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7152 {
7153 new_return(4);
7154 }
7155
7156 18 writesize=0;
7157
7158 //finally... section data
7159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7160 {
7161 new_return(5);
7162 }
7163
7164
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7165 {
7166 9 section_size=writesize;
7167 9 }
7168 18 }
7169
7170
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7171 {
7172 displayinfo("Error: writerules()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7173 }
7174
7175 9 new_return(0);
7176 }
7177
7178
7179 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7180 {
7181 //these are here to bypass compiler warnings about unused arguments
7182 9 Header=Header;
7183
7184 9 dword section_id=ID_DOORS;
7185 9 dword section_version=V_DOORS;
7186 9 dword section_size=0;
7187
7188 //section id
7189
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7190 {
7191 new_return(1);
7192 }
7193
7194 //section version info
7195
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7196 {
7197 new_return(2);
7198 }
7199
7200
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7201 {
7202 new_return(3);
7203 }
7204
7205
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7206 {
7207 18 fake_pack_writing=(writecycle==0);
7208
7209 //section size
7210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7211 {
7212 new_return(4);
7213 }
7214
7215 18 writesize=0;
7216
7217 //finally... section data
7218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7219 {
7220 new_return(5);
7221 }
7222
7223
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 320 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7224 {
7225 //name
7226 char name[21];
7227 320 memset(name, 21, (char)0);
7228 320 strcpy(name, DoorComboSetNames[i].c_str());
7229
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7230 {
7231 new_return(6);
7232 }
7233
7234 //up door
7235
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7236 {
7237
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7238 {
7239
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7240 {
7241 new_return(7);
7242 }
7243 11520 }
7244 2880 }
7245
7246
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7247 {
7248
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7249 {
7250
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7251 {
7252 new_return(8);
7253 }
7254 11520 }
7255 2880 }
7256
7257 //down door
7258
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7259 {
7260
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7261 {
7262
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7263 {
7264 new_return(9);
7265 }
7266 11520 }
7267 2880 }
7268
7269
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7270 {
7271
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7272 {
7273
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7274 {
7275 new_return(10);
7276 }
7277 11520 }
7278 2880 }
7279
7280
7281 //left door
7282
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7283 {
7284
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7285 {
7286
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7287
7288 {
7289 new_return(11);
7290 }
7291 17280 }
7292 2880 }
7293
7294
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7295 {
7296
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7297 {
7298
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7299 {
7300 new_return(12);
7301 }
7302 17280 }
7303 2880 }
7304
7305 //right door
7306
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7307 {
7308
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7309 {
7310
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7311 {
7312 new_return(13);
7313 }
7314 17280 }
7315 2880 }
7316
7317
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7318 {
7319
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7320 {
7321
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7322 {
7323 new_return(14);
7324 }
7325 17280 }
7326 2880 }
7327
7328
7329 //up bomb rubble
7330
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7331 {
7332
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7333 {
7334 new_return(15);
7335 }
7336 640 }
7337
7338
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7339 {
7340
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7341 {
7342 new_return(16);
7343 }
7344 640 }
7345
7346 //down bomb rubble
7347
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7348 {
7349
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7350 {
7351 new_return(17);
7352 }
7353 640 }
7354
7355
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7356 {
7357
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7358 {
7359 new_return(18);
7360 }
7361 640 }
7362
7363 //left bomb rubble
7364
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7365 {
7366
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7367 {
7368 new_return(19);
7369 }
7370 960 }
7371
7372
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7373 {
7374
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7375 {
7376 new_return(20);
7377 }
7378 960 }
7379
7380 //right bomb rubble
7381
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7382 {
7383
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7384 {
7385 new_return(21);
7386 }
7387 960 }
7388
7389
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7390 {
7391
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7392 {
7393 new_return(22);
7394 }
7395 960 }
7396
7397 //walkthrough stuff
7398
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7399 {
7400
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7401 {
7402 new_return(23);
7403 }
7404 1280 }
7405
7406
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7407 {
7408
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7409 {
7410 new_return(24);
7411 }
7412 1280 }
7413
7414 //flags
7415
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 640 times.
960 for(int32_t j=0; j<2; j++)
7416 {
7417
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7418 {
7419 new_return(25);
7420 }
7421 640 }
7422 320 }
7423
7424
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7425 {
7426 9 section_size=writesize;
7427 9 }
7428 18 }
7429
7430
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7431 {
7432 displayinfo("Error: writedoorcombosets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7433 }
7434
7435 9 new_return(0);
7436 }
7437
7438 9216 int32_t write_one_dmap(PACKFILE* f, int index)
7439 {
7440 9216 DMaps[index].validate_subscreens();
7441
7442
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].map,f))
7443 {
7444 new_return(6);
7445 }
7446
7447
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].level,f))
7448 {
7449 new_return(7);
7450 }
7451
7452
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].xoff,f))
7453 {
7454 new_return(8);
7455 }
7456
7457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].compass,f))
7458 {
7459 new_return(9);
7460 }
7461
7462
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].color,f))
7463 {
7464 new_return(10);
7465 }
7466
7467
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].midi,f))
7468 {
7469 new_return(11);
7470 }
7471
7472
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].cont,f))
7473 {
7474 new_return(12);
7475 }
7476
7477
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].type,f))
7478 {
7479 new_return(13);
7480 }
7481
7482
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7483 {
7484
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[index].grid[j],f))
7485 {
7486 new_return(14);
7487 }
7488 73728 }
7489
7490
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].name,sizeof(DMaps[0].name)-1,f))
7491 {
7492 new_return(15);
7493 }
7494
7495
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[index].title,f))
7496 {
7497 new_return(16);
7498 }
7499
7500
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].intro,sizeof(DMaps[0].intro)-1,f))
7501 {
7502 new_return(17);
7503 }
7504
7505
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[0],f))
7506 {
7507 new_return(18);
7508 }
7509
7510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[0],f))
7511 {
7512 new_return(19);
7513 }
7514
7515
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[1],f))
7516 {
7517 new_return(20);
7518 }
7519
7520
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[1],f))
7521 {
7522 new_return(21);
7523 }
7524
7525
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[0],f))
7526 {
7527 new_return(22);
7528 }
7529
7530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[0],f))
7531 {
7532 new_return(23);
7533 }
7534
7535
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[1],f))
7536 {
7537 new_return(24);
7538 }
7539
7540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[1],f))
7541 {
7542 new_return(25);
7543 }
7544
7545
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7546 {
7547 new_return(26);
7548 }
7549
7550
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].tmusictrack,f))
7551 {
7552 new_return(25);
7553 }
7554
7555
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].active_subscreen,f))
7556 {
7557 new_return(26);
7558 }
7559
7560
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].passive_subscreen,f))
7561 {
7562 new_return(27);
7563 }
7564
7565 byte disabled[32];
7566 9216 memset(disabled,0,32);
7567
7568
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7569 {
7570
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[index].disableditems[j])
7571 {
7572 disabled[j/8] |= (1 << (j%8));
7573 }
7574 2359296 }
7575
7576
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7577 {
7578 new_return(28);
7579 }
7580
7581
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].flags,f))
7582 new_return(29);
7583
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].sideview,f))
7584 new_return(30);
7585
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].script,f))
7586 new_return(31);
7587
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7588
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].initD[q],f))
7589 new_return(32);
7590
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7591
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7592
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[index].initD_label[q][w],f))
7593 73728 new_return(33);
7594
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].active_sub_script,f))
7595 new_return(34);
7596
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].passive_sub_script,f))
7597 new_return(35);
7598
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7599
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].sub_initD[q],f))
7600 new_return(36);
7601
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7602
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7603
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].sub_initD_label[q][w],f))
7604 73728 new_return(37);
7605
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].onmap_script,f))
7606 new_return(38);
7607
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7608
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].onmap_initD[q],f))
7609 new_return(39);
7610
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7611
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7612
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].onmap_initD_label[q][w],f))
7613 73728 new_return(40);
7614
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].mirrorDMap,f))
7615 new_return(41);
7616
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_start, f))
7617 new_return(42);
7618
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_end, f))
7619 new_return(43);
7620
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_in, f))
7621 new_return(44);
7622
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_out, f))
7623 new_return(45);
7624
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].overlay_subscreen, f))
7625 new_return(46);
7626
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].intro_string_id, f))
7627 new_return(47);
7628
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[index].flags & dmfCUSTOM_GRAVITY)
7629 {
7630 if (!p_iputzf(DMaps[index].dmap_gravity, f))
7631 new_return(48);
7632 if (!p_iputzf(DMaps[index].dmap_terminal_v, f))
7633 new_return(49);
7634 }
7635
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].map_subscreen, f))
7636 new_return(50);
7637
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].floor, f))
7638 new_return(51);
7639 9216 return 0;
7640 }
7641 9 int32_t writedmaps(PACKFILE *f, word, word, word start_dmap, word max_dmaps)
7642 {
7643 9 word dmap_count=count_dmaps();
7644 9 dword section_id=ID_DMAPS;
7645 9 dword section_version=V_DMAPS;
7646 9 dword section_size=0;
7647
7648 //section id
7649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7650 {
7651 new_return(1);
7652 }
7653
7654 //section version info
7655
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7656 {
7657 new_return(2);
7658 }
7659
7660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7661 {
7662 new_return(3);
7663 }
7664
7665
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7666 {
7667 18 fake_pack_writing=(writecycle==0);
7668
7669 //section size
7670
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7671 {
7672 new_return(4);
7673 }
7674
7675 18 writesize=0;
7676
7677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7679
7680 //finally... section data
7681
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7682 {
7683 new_return(5);
7684 }
7685
7686
7687
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7688 {
7689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (auto ret = write_one_dmap(f, i))
7690 return ret;
7691 9216 }
7692
7693
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7694 {
7695 9 section_size=writesize;
7696 9 }
7697 18 }
7698
7699
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7700 {
7701 displayinfo("Error: writedmaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7702 }
7703
7704 9 new_return(0);
7705 9 }
7706
7707 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7708 {
7709 //these are here to bypass compiler warnings about unused arguments
7710 9 Header=Header;
7711
7712 9 dword section_id=ID_COLORS;
7713 9 dword section_version=V_COLORS;
7714 9 dword section_size = 0;
7715
7716 //section id
7717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7718 {
7719 new_return(1);
7720 }
7721
7722
7723 //section version info
7724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7725 {
7726 new_return(2);
7727 }
7728
7729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7730 {
7731 new_return(3);
7732 }
7733
7734
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7735 {
7736 18 fake_pack_writing=(writecycle==0);
7737
7738 //section size
7739
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7740 {
7741 new_return(4);
7742 }
7743
7744 18 writesize=0;
7745
7746
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7747 {
7748 new_return(5);
7749 }
7750
7751
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7752 {
7753 new_return(6);
7754 }
7755
7756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7757 {
7758 new_return(7);
7759 }
7760
7761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7762 {
7763 new_return(8);
7764 }
7765
7766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7767 {
7768 new_return(9);
7769 }
7770
7771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7772 {
7773 new_return(10);
7774 }
7775
7776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7777 {
7778 new_return(11);
7779 }
7780
7781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7782 {
7783 new_return(12);
7784 }
7785
7786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7787 {
7788 new_return(13);
7789 }
7790
7791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7792 {
7793 new_return(14);
7794 }
7795
7796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7797 {
7798 new_return(15);
7799 }
7800
7801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7802 {
7803 new_return(16);
7804 }
7805
7806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7807 {
7808 new_return(17);
7809 }
7810
7811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7812 {
7813 new_return(18);
7814 }
7815
7816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7817 {
7818 new_return(19);
7819 }
7820
7821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7822 {
7823 new_return(20);
7824 }
7825
7826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7827 {
7828 new_return(21);
7829 }
7830
7831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7832 {
7833 new_return(22);
7834 }
7835
7836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7837 {
7838 new_return(23);
7839 }
7840
7841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7842 {
7843 new_return(24);
7844 }
7845
7846
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7847 {
7848 new_return(31);
7849 }
7850
7851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7852 {
7853 new_return(32);
7854 }
7855
7856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7857 {
7858 new_return(33);
7859 }
7860
7861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7862 {
7863 new_return(34);
7864 }
7865
7866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7867 {
7868 new_return(35);
7869 }
7870
7871
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7872 {
7873 new_return(36);
7874 }
7875
7876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7877 {
7878 new_return(37);
7879 }
7880
7881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7882 {
7883 new_return(38);
7884 }
7885
7886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7887 {
7888 new_return(39);
7889 }
7890
7891
7892
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7893 {
7894 9 section_size=writesize;
7895 9 }
7896 18 }
7897
7898
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7899 {
7900 displayinfo("Error: writemisccolors()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7901 }
7902
7903 9 new_return(0);
7904 }
7905
7906 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7907 {
7908 //these are here to bypass compiler warnings about unused arguments
7909 9 Header=Header;
7910
7911 9 dword section_id=ID_ICONS;
7912 9 dword section_version=V_ICONS;
7913 9 dword section_size = 0;
7914
7915 //section id
7916
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7917 {
7918 new_return(1);
7919 }
7920
7921 //section version info
7922
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7923 {
7924 new_return(2);
7925 }
7926
7927
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7928 {
7929 new_return(3);
7930 }
7931
7932
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7933 {
7934 18 fake_pack_writing=(writecycle==0);
7935
7936 //section size
7937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7938 {
7939 new_return(4);
7940 }
7941
7942 18 writesize=0;
7943
7944
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7945 {
7946
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7947 {
7948 new_return(5);
7949 }
7950 72 }
7951
7952
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7953 {
7954 9 section_size=writesize;
7955 9 }
7956 18 }
7957
7958
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7959 {
7960 displayinfo("Error: writegameicons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7961 }
7962
7963 9 new_return(0);
7964 }
7965
7966 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7967 {
7968 //these are here to bypass compiler warnings about unused arguments
7969 9 Header=Header;
7970
7971 9 dword section_id=ID_MISC;
7972 9 dword section_version=V_MISC;
7973 9 word shops=count_shops(&QMisc);
7974 9 word infos=count_infos(&QMisc);
7975 9 word warprings=count_warprings(&QMisc);
7976 9 word triforces=8;
7977 9 dword section_size = 0;
7978
7979 //section id
7980
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7981 {
7982 new_return(1);
7983 }
7984
7985
7986 //section version info
7987
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7988 {
7989 new_return(2);
7990 }
7991
7992
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7993 {
7994 new_return(3);
7995 }
7996
7997
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7998 {
7999 18 fake_pack_writing=(writecycle==0);
8000
8001 //section size
8002
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8003 {
8004 new_return(4);
8005 }
8006
8007 18 writesize=0;
8008
8009 //shops
8010
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8011 {
8012 new_return(5);
8013 }
8014
8015
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8016 {
8017
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8018 {
8019 new_return(6);
8020 }
8021
8022
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8023 {
8024
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8025 {
8026 new_return(7);
8027 }
8028 480 }
8029
8030
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8031 {
8032
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8033 {
8034 new_return(8);
8035 }
8036 480 }
8037
8038
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8039 {
8040
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8041 {
8042 new_return(9);
8043 }
8044 480 }
8045 160 }
8046
8047 //infos
8048
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8049 {
8050 new_return(10);
8051 }
8052
8053
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8054 {
8055
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8056 {
8057 new_return(11);
8058 }
8059
8060
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8061 {
8062
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8063 {
8064 new_return(12);
8065 }
8066 480 }
8067
8068
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8069 {
8070
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8071 {
8072 new_return(13);
8073 }
8074 480 }
8075 160 }
8076
8077 //warp rings
8078
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8079 {
8080 new_return(14);
8081 }
8082
8083
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8084 {
8085
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8086 {
8087
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8088 {
8089 new_return(15);
8090 }
8091 1872 }
8092
8093
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8094 {
8095
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8096 {
8097 new_return(16);
8098 }
8099 1872 }
8100
8101
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8102 {
8103 new_return(17);
8104 }
8105 208 }
8106
8107 //triforce pieces
8108
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8109 {
8110
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8111 {
8112 new_return(18);
8113 }
8114 144 }
8115
8116 //end string
8117
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8118 {
8119 new_return(19);
8120 }
8121
8122 //V_MISC >= 8
8123
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8124 {
8125
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8126 {
8127
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8128 {
8129 new_return(20);
8130 }
8131 480 }
8132 160 }
8133 //V_MISC >= 9
8134
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8135 {
8136
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8137 new_return(21);
8138 576 }
8139
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8140 {
8141
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 73728 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8142
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8143 new_return(22);
8144 576 }
8145 //V_MISC >= 11
8146
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8147 new_return(23);
8148
8149 //V_MISC >= 12
8150
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8151 {
8152
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8153 new_return(24);
8154 4608 }
8155
8156 //V_MISC >= 13
8157
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8158 {
8159 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8160
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8161 new_return(25);
8162
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8163 {
8164
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8165 new_return(25);
8166
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8167 new_return(25);
8168 3456 }
8169
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8170 new_return(25);
8171
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8172 new_return(25);
8173 1152 }
8174
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8175 {
8176 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8177
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8178 new_return(26);
8179
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8180 {
8181
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8182 new_return(26);
8183
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8184 new_return(26);
8185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_putc(bst->cset[j], f))
8186 new_return(26);
8187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->price[j], f))
8188 new_return(26);
8189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8190 new_return(26);
8191 13824 }
8192 4608 }
8193
8194 //V_MISC >= 14
8195
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8196 {
8197
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8198 new_return(27);
8199 4608 }
8200
8201 //V_MISC >= 17
8202 18 byte save_menu_count = 0;
8203
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(size_t q = 0; q < NUM_SAVE_MENUS; ++q)
8204
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if (!QMisc.save_menus[q].is_empty())
8205 save_menu_count = q+1;
8206
8207
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(save_menu_count, f))
8208 new_return(28);
8209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(size_t q = 0; q < save_menu_count; ++q)
8210 {
8211 SaveMenu const& menu = QMisc.save_menus[q];
8212
8213 byte empty = menu.is_empty() ? 1 : 0;
8214
8215 if (!p_putc(empty, f))
8216 new_return(29);
8217 if (empty) continue;
8218
8219 if (!p_putcstr(menu.name, f))
8220 new_return(30);
8221
8222 if (!p_iputw(menu.flags, f))
8223 new_return(31);
8224
8225 if (!p_iputl(menu.cursor_tile, f))
8226 new_return(32);
8227
8228 if (!p_putc(menu.cursor_cset, f))
8229 new_return(33);
8230
8231 if (!p_putc(menu.cursor_sfx, f))
8232 new_return(34);
8233
8234 if (!p_putc(menu.choose_sfx, f))
8235 new_return(35);
8236
8237 if (!p_putc(menu.bg_color, f))
8238 new_return(36);
8239
8240 if (!p_putc(menu.hspace, f))
8241 new_return(37);
8242
8243 if (!p_putc(menu.vspace, f))
8244 new_return(38);
8245
8246 if (!p_putc(menu.opt_x, f))
8247 new_return(39);
8248
8249 if (!p_putc(menu.opt_y, f))
8250 new_return(40);
8251
8252 if (!p_putc(menu.text_align, f))
8253 new_return(41);
8254
8255 if (!p_putc(menu.textbox_align, f))
8256 new_return(42);
8257
8258 if (!p_iputw(menu.close_frames, f))
8259 new_return(43);
8260
8261 if (!p_putc(menu.close_flash_rate, f))
8262 new_return(44);
8263
8264 if (!p_iputw(menu.midi, f))
8265 new_return(45);
8266
8267 if (!p_iputl(menu.bg_tile, f))
8268 new_return(46);
8269
8270 if (!p_putc(menu.bg_cset, f))
8271 new_return(47);
8272
8273 if (!p_putc(menu.bg_tw, f))
8274 new_return(48);
8275
8276 if (!p_putc(menu.bg_th, f))
8277 new_return(49);
8278
8279 byte opt_count = zc_min(menu.options.size(), MAX_SAVEMENU_OPTIONS);
8280 if (!p_putc(opt_count, f))
8281 new_return(50);
8282
8283 for (size_t q = 0; q < opt_count; ++q)
8284 {
8285 SaveMenuOption const& opt = menu.options[q];
8286
8287 if (!p_putcstr(opt.text, f))
8288 new_return(51);
8289
8290 if (!p_iputw(opt.flags, f))
8291 new_return(52);
8292
8293 if (!p_putc(opt.color, f))
8294 new_return(53);
8295
8296 if (!p_putc(opt.picked_color, f))
8297 new_return(54);
8298
8299 if (!p_iputl(opt.font, f))
8300 new_return(55);
8301
8302 if (!p_iputw(opt.gen_script, f))
8303 new_return(56);
8304 }
8305 }
8306
8307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_game_over, f))
8308 new_return(57);
8309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_f6, f))
8310 new_return(58);
8311
8312
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8313 {
8314 9 section_size=writesize;
8315 9 }
8316 18 }
8317
8318
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8319 {
8320 displayinfo("Error: writemisc()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8321 }
8322
8323 9 new_return(0);
8324 }
8325
8326 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8327 {
8328 //these are here to bypass compiler warnings about unused arguments
8329 9 Header=Header;
8330
8331 9 dword section_id=ID_ITEMS;
8332 9 dword section_version=V_ITEMS;
8333 // dword section_size=0;
8334 9 dword section_size = 0;
8335
8336 //section id
8337
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8338 {
8339 new_return(1);
8340 }
8341
8342 //section version info
8343
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8344 {
8345 new_return(2);
8346 }
8347
8348
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8349 {
8350 new_return(3);
8351 }
8352
8353
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8354 {
8355 18 fake_pack_writing=(writecycle==0);
8356
8357 //section size
8358
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8359 {
8360 new_return(4);
8361 }
8362
8363 18 writesize=0;
8364
8365 //finally... section data
8366
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8367 {
8368 new_return(5);
8369 }
8370
8371
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8372 {
8373
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8374 {
8375 new_return(5);
8376 }
8377 4608 }
8378
8379
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8380 {
8381
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8382 {
8383 new_return(6);
8384 }
8385
8386
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8387 {
8388 new_return(7);
8389 }
8390
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8392 {
8393 new_return(8);
8394 }
8395
8396
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8397 {
8398 new_return(9);
8399 }
8400
8401
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8402 {
8403 new_return(10);
8404 }
8405
8406
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8407 {
8408 new_return(11);
8409 }
8410
8411
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8412 {
8413 new_return(12);
8414 }
8415
8416
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8417 {
8418 new_return(13);
8419 }
8420
8421
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8422 {
8423 new_return(14);
8424 }
8425
8426
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8427 {
8428 new_return(14);
8429 }
8430
8431
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8432 {
8433 new_return(15);
8434 }
8435
8436
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8437 {
8438 new_return(16);
8439 }
8440
8441
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8442 {
8443 new_return(17);
8444 }
8445
8446
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8447 {
8448 new_return(18);
8449 }
8450
8451
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8452 {
8453 new_return(19);
8454 }
8455
8456
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8457 {
8458 new_return(21);
8459 }
8460
8461
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8462 {
8463 new_return(22);
8464 }
8465
8466
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8467 {
8468 new_return(23);
8469 }
8470
8471
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8472 {
8473
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8474 {
8475 new_return(24);
8476 }
8477 36864 }
8478
8479
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8480 {
8481
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8482 {
8483 new_return(25);
8484 }
8485 9216 }
8486
8487
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8488 {
8489 new_return(26);
8490 }
8491
8492
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8493 {
8494 new_return(27);
8495 }
8496
8497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8498 {
8499 new_return(28);
8500 }
8501
8502
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8503 {
8504 new_return(29);
8505 }
8506
8507
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8508 {
8509 new_return(30);
8510 }
8511
8512
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8513 {
8514 new_return(31);
8515 }
8516
8517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8518 {
8519 new_return(32);
8520 }
8521
8522
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8523 {
8524 new_return(33);
8525 }
8526
8527
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8528 {
8529 new_return(34);
8530 }
8531
8532
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8533 {
8534 new_return(35);
8535 }
8536
8537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8538 {
8539 new_return(36);
8540 }
8541
8542
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8543 {
8544 new_return(37);
8545 }
8546
8547
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8548 {
8549 new_return(38);
8550 }
8551
8552
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8553 {
8554
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8555 {
8556 new_return(39);
8557 }
8558 9216 }
8559
8560
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8561 {
8562 new_return(40);
8563 }
8564
8565
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8566 {
8567 new_return(41);
8568 }
8569
8570
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8571 {
8572 new_return(42);
8573 }
8574
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8576 {
8577 new_return(43);
8578 }
8579
8580
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8581 {
8582 new_return(44);
8583 }
8584
8585
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8586 {
8587 new_return(45);
8588 }
8589
8590
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8591 {
8592 new_return(46);
8593 }
8594
8595
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8596 {
8597 new_return(47);
8598 }
8599
8600
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8601 {
8602 new_return(48);
8603 }
8604
8605
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8606 {
8607 new_return(48);
8608 }
8609
8610 //New itemdata vars -Z
8611 //! version 27
8612
8613
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8614 {
8615 new_return(51);
8616 }
8617
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8618 {
8619 new_return(52);
8620 }
8621
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8622
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8623 {
8624 new_return(53);
8625 }
8626 46080 }
8627 //version 28
8628
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8629 {
8630 new_return(54);
8631 }
8632
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8633 {
8634
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8635 {
8636 new_return(56);
8637 }
8638 9216 }
8639
8640
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8641 {
8642 new_return(57);
8643 }
8644
8645
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8647 {
8648 new_return(58);
8649 }
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8651 {
8652 new_return(59);
8653 }
8654
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8655 {
8656 new_return(60);
8657 }
8658
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8659 {
8660 new_return(61);
8661 }
8662
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8663 {
8664 new_return(62);
8665 }
8666
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8667 {
8668 new_return(63);
8669 }
8670
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8671 {
8672 new_return(64);
8673 }
8674
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8675 {
8676 new_return(73);
8677 }
8678
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8679 {
8680
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8681 {
8682 new_return(74);
8683 }
8684 9216 }
8685
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8686 {
8687 new_return(75);
8688 }
8689
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8690 {
8691 new_return(76);
8692 }
8693
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8694 {
8695 new_return(77);
8696 }
8697
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8698 {
8699 new_return(81);
8700 }
8701
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8702 {
8703 new_return(82);
8704 }
8705
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8706 {
8707 new_return(83);
8708 }
8709
8710
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8711 {
8712
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8713 {
8714 new_return(84);
8715 }
8716 9216 }
8717
8718 //InitD[] labels
8719
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8720 {
8721
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8722 {
8723
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8724 {
8725 new_return(85);
8726 }
8727 2396160 }
8728
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8729 {
8730
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8731 {
8732 new_return(87);
8733 }
8734 2396160 }
8735
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8736 {
8737 new_return(88);
8738 }
8739 36864 }
8740
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8741 {
8742
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8743 {
8744 new_return(89);
8745 }
8746
8747 9216 }
8748
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8749 {
8750 new_return(90);
8751 }
8752
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8753 {
8754 new_return(91);
8755 }
8756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8757
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8758 new_return(92);
8759
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8760 new_return(95);
8761
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8762 new_return(96);
8763
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8764 new_return(97);
8765
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8766 return ret;
8767
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8768 new_return(98);
8769
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8770
8771
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8772 {
8773 9 section_size=writesize;
8774 9 }
8775 18 }
8776
8777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8778 {
8779 displayinfo("Error: writeitems()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8780 }
8781
8782 9 new_return(0);
8783 9 }
8784
8785 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8786 {
8787 //these are here to bypass compiler warnings about unused arguments
8788 9 Header=Header;
8789
8790 9 dword section_id=ID_WEAPONS;
8791 9 dword section_version=V_WEAPONS;
8792 9 dword section_size = 0;
8793
8794 //section id
8795
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8796 {
8797 new_return(1);
8798 }
8799
8800 //section version info
8801
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8802 {
8803 new_return(2);
8804 }
8805
8806
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8807 {
8808 new_return(3);
8809 }
8810
8811
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8812 {
8813 18 fake_pack_writing=(writecycle==0);
8814
8815 //section size
8816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8817 {
8818 new_return(4);
8819 }
8820
8821 18 writesize=0;
8822
8823 //finally... section data
8824
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8825 {
8826 new_return(5);
8827 }
8828
8829
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8830 {
8831
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8832 {
8833 new_return(5);
8834 }
8835 4608 }
8836
8837
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8838 {
8839
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8840 {
8841 new_return(7);
8842 }
8843
8844
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8845 {
8846 new_return(8);
8847 }
8848
8849
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8850 {
8851 new_return(9);
8852 }
8853
8854
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8855 {
8856 new_return(10);
8857 }
8858
8859
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8860 {
8861 new_return(11);
8862 }
8863
8864
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8865 {
8866 new_return(12);
8867 }
8868
8869
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8870 {
8871 new_return(12);
8872 }
8873 4608 }
8874
8875
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8876 {
8877 9 section_size=writesize;
8878 9 }
8879 18 }
8880
8881
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8882 {
8883 displayinfo("Error: writeweapons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8884 }
8885
8886 9 new_return(0);
8887 }
8888
8889 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8890 {
8891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8892 return qe_invalid;
8893
8894 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8895 12784 bool is_0x80_screen = j >= 0x80;
8896
8897
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8898 return qe_invalid;
8899
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8900 4404 return qe_OK;
8901 //Calculate what needs writing
8902 8380 uint32_t scr_has_flags = 0;
8903
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8904
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8905 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8906
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8907 446 scr_has_flags |= SCRHAS_ITEM;
8908
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8909 28 scr_has_flags |= SCRHAS_TWARP;
8910
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8911 {
8912
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8913
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8914
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8915 {
8916 176 scr_has_flags |= SCRHAS_TWARP;
8917 176 break;
8918 }
8919 32706 }
8920
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8921
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8922 36 scr_has_flags |= SCRHAS_SWARP;
8923
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8924 {
8925
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8926
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8927
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8928 {
8929 4270 scr_has_flags |= SCRHAS_SWARP;
8930 4270 break;
8931 }
8932 16298 }
8933
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8934 44 scr_has_flags |= SCRHAS_WARPRET;
8935
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8936 {
8937
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8938 {
8939 784 scr_has_flags |= SCRHAS_WARPRET;
8940 784 break;
8941 }
8942 30208 }
8943
8944
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8945 scr_has_flags |= SCRHAS_LAYERS;
8946
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8947 {
8948
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8949
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8950 {
8951 966 scr_has_flags |= SCRHAS_LAYERS;
8952 966 break;
8953 }
8954 44532 }
8955
8956
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8957 10 scr_has_flags |= SCRHAS_MAZE;
8958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8959 scr_has_flags |= SCRHAS_MAZE;
8960
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8961 {
8962
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8963 {
8964 scr_has_flags |= SCRHAS_MAZE;
8965 break;
8966 }
8967 33480 }
8968
8969
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8970
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8971
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8972 2968 scr_has_flags |= SCRHAS_D_S_U;
8973
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8974 {
8975
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8976 {
8977 5212 scr_has_flags |= SCRHAS_D_S_U;
8978 5212 break;
8979 }
8980 800 }
8981
8982
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8983
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8984
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8985
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8986
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8987
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8988 8380 scr_has_flags |= SCRHAS_FLAGS;
8989
8990
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8991 58 scr_has_flags |= SCRHAS_ENEMY;
8992
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8993 {
8994
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8995 {
8996 1014 scr_has_flags |= SCRHAS_ENEMY;
8997 1014 break;
8998 }
8999 73086 }
9000
9001
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
9002 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
9003 8380 scr_has_flags |= SCRHAS_CARRY;
9004
9005
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9006 22 scr_has_flags |= SCRHAS_SCRIPT;
9007
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9008 {
9009
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9010 {
9011 scr_has_flags |= SCRHAS_SCRIPT;
9012 break;
9013 }
9014 66864 }
9015
9016
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9017 {
9018
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9019
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9020
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9021 {
9022 3076 scr_has_flags |= SCRHAS_SECRETS;
9023 3076 break;
9024 }
9025 680916 }
9026
9027
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9028 {
9029
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9030
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9031 {
9032 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9033 5360 break;
9034 }
9035 568532 }
9036
9037
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9038
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9039
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9040 || screen.timedwarptics || screen.screen_midi != -1
9041 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9042 8380 scr_has_flags |= SCRHAS_MISC;
9043
9044
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9045 return qe_invalid;
9046
9047 //Write stuff
9048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9049 {
9050
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9051 return qe_invalid;
9052
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9053 return qe_invalid;
9054
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9055 return qe_invalid;
9056
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9057 return qe_invalid;
9058
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9059 return qe_invalid;
9060
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9061 return qe_invalid;
9062
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9063 return qe_invalid;
9064 8380 }
9065
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9066 {
9067
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9068 return qe_invalid;
9069
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9070 return qe_invalid;
9071
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9072 return qe_invalid;
9073
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9074 return qe_invalid;
9075 446 }
9076
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9077 {
9078
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9079 return qe_invalid;
9080 4374 }
9081
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9082 {
9083
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9084 {
9085
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9086 return qe_invalid;
9087 816 }
9088
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9089 {
9090
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9091 return qe_invalid;
9092 816 }
9093
9094
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9095 {
9096
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9097 return qe_invalid;
9098 816 }
9099
9100
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9101 return qe_invalid;
9102 204 }
9103
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9104 {
9105
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9106 {
9107
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9108 return qe_invalid;
9109 17224 }
9110
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9111 {
9112
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9113 return qe_invalid;
9114 17224 }
9115
9116
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9117 {
9118
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9119 return qe_invalid;
9120 17224 }
9121
9122
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9123 return qe_invalid;
9124
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9125 return qe_invalid;
9126 4306 }
9127
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9128 {
9129
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9130 {
9131
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9132 return qe_invalid;
9133 3312 }
9134
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9135 {
9136
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9137 return qe_invalid;
9138 3312 }
9139
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9140 return qe_invalid;
9141
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9142 return qe_invalid;
9143 828 }
9144
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9145 {
9146
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9147 {
9148
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9149 return qe_invalid;
9150 5796 }
9151
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9152 {
9153
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9154 return qe_invalid;
9155 5796 }
9156
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9157 {
9158
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9159 return qe_invalid;
9160 5796 }
9161
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9162 return qe_invalid;
9163
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9164 return qe_invalid;
9165 966 }
9166
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9167 {
9168
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9169 {
9170
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9171 return qe_invalid;
9172 40 }
9173
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9174 return qe_invalid;
9175
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9176 return qe_invalid;
9177 10 }
9178
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9179 {
9180
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9181 return qe_invalid;
9182
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9183 {
9184
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9185 return qe_invalid;
9186 32720 }
9187
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9188 return qe_invalid;
9189
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9190 return qe_invalid;
9191
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9192 return qe_invalid;
9193
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9194 return qe_invalid;
9195 8180 }
9196
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9197 {
9198
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9199 return qe_invalid;
9200
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9201 return qe_invalid;
9202
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9203 return qe_invalid;
9204
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9205 return qe_invalid;
9206
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9207 return qe_invalid;
9208
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9209 return qe_invalid;
9210
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9211 return qe_invalid;
9212
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9213 return qe_invalid;
9214
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9215 return qe_invalid;
9216
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9217 return qe_invalid;
9218
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9219 return qe_invalid;
9220 1294 }
9221
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9222 {
9223
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9224 {
9225
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9226 return qe_invalid;
9227 10720 }
9228
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9229 return qe_invalid;
9230 1072 }
9231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9232 {
9233
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9236 return qe_invalid;
9237
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9238 return qe_invalid;
9239
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9240 return qe_invalid;
9241
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9244 return qe_invalid;
9245 8380 }
9246
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9247 {
9248
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9249 return qe_invalid;
9250
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9251 return qe_invalid;
9252
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9253 {
9254
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9255 return qe_invalid;
9256 176 }
9257 22 }
9258
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9259 {
9260
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9261 {
9262
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9263 return qe_invalid;
9264 393728 }
9265
9266
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9267 {
9268
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9269 return qe_invalid;
9270 393728 }
9271
9272
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9273 {
9274
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9275 return qe_invalid;
9276 393728 }
9277 3076 }
9278
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9279 {
9280
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9281 {
9282
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9283 return qe_invalid;
9284 943360 }
9285
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9286 {
9287
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9288 return qe_invalid;
9289 943360 }
9290
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9291 {
9292
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9293 return qe_invalid;
9294 943360 }
9295 5360 }
9296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9297 {
9298
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9299 return qe_invalid;
9300
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9301 return qe_invalid;
9302
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9303 return qe_invalid;
9304
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9305 return qe_invalid;
9306
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9307 return qe_invalid;
9308
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9309 return qe_invalid;
9310
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9311 return qe_invalid;
9312
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9313 return qe_invalid;
9314
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9315 return qe_invalid;
9316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9317 return qe_invalid;
9318
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9319 return qe_invalid;
9320 8380 }
9321
9322 8380 dword numffc = screen.numFFC();
9323
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9324 return qe_invalid;
9325
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9326 {
9327 245678 ffcdata const& tempffc = screen.ffcs[k];
9328
9329
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9330 return qe_invalid;
9331
9332
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9333 243364 continue;
9334
9335
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9336 return qe_invalid;
9337
9338
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9339 return qe_invalid;
9340
9341
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9342 return qe_invalid;
9343
9344
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9345 return qe_invalid;
9346
9347
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9348 return qe_invalid;
9349
9350
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9351 return qe_invalid;
9352
9353
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9354 return qe_invalid;
9355
9356
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9357 return qe_invalid;
9358
9359
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9360 return qe_invalid;
9361
9362
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9363 return qe_invalid;
9364
9365
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9366 return qe_invalid;
9367
9368
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9369 return qe_invalid;
9370
9371
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9372 return qe_invalid;
9373
9374
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9375 return qe_invalid;
9376
9377
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9378 return qe_invalid;
9379
9380
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9381 {
9382
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9383 return qe_invalid;
9384 18512 }
9385
9386
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9387 return qe_invalid;
9388 2314 }
9389
9390
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9391 return qe_invalid;
9392
9393
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9394 {
9395
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9396 return qe_invalid;
9397
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9398 return qe_invalid;
9399 6 }
9400
9401 8380 return qe_OK;
9402 12784 }
9403
9404 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9405 {
9406 9 dword section_id=ID_MAPS;
9407 9 dword section_version=V_MAPS;
9408 9 dword section_size = 0;
9409
9410 //section id
9411
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9412 {
9413 new_return(1);
9414 }
9415
9416 //section version info
9417
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9418 {
9419 new_return(2);
9420 }
9421
9422
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9423 {
9424 new_return(3);
9425 }
9426
9427
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9428 {
9429 18 fake_pack_writing=(writecycle==0);
9430
9431 //section size
9432
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9433 {
9434 new_return(4);
9435 }
9436
9437 18 writesize=0;
9438
9439
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9440 {
9441 new_return(5);
9442 }
9443 18 map_infos.resize(map_count);
9444
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 100 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9445 {
9446 100 byte valid = 0;
9447
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9448 {
9449
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9450 break;
9451 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9452
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9453 {
9454 94 valid = 1;
9455 94 break;
9456 }
9457 1188 }
9458
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9459 {
9460 new_return(6);
9461 }
9462
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9463
9464 { //per-map info
9465 94 auto const& mapinf = map_infos[i];
9466
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9467 {
9468
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9469 new_return(7);
9470 564 }
9471
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9472 new_return(9);
9473
9474
9475
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9476 {
9477
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9478 {
9479
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9480 {
9481 new_return(8);
9482 }
9483 6016 }
9484 752 }
9485 }
9486
9487
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9488 12784 writemapscreen(f,i,j);
9489 94 }
9490
9491
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9492 {
9493 9 section_size=writesize;
9494 9 }
9495 18 }
9496
9497
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9498 {
9499 displayinfo("Error: writemaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9500 }
9501
9502 9 new_return(0);
9503 }
9504
9505 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9506 {
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9508 return 22;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9510 return 22;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9512 return 23;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9514 return 34;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9516 return 35;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9518 return 36;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9520 return 37;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9522 return 38;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9524 return 39;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9526 return 40;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9528 return 41;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9530 return 42;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9532 return 43;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9534 return 44;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9536 return 45;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9538 return 46;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9540 return 47;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9542 return 48;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9544 return 49;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9546 return 50;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9548 return 51;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9550 return 52;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9552 return 53;
9553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9554 return 69;
9555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9556 return 70;
9557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9558 return 71;
9559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9560 return 72;
9561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9562 return 76;
9563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9564 return 77;
9565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9566 return 89;
9567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9568 return 90;
9569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9570 return 91;
9571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9572 return 92;
9573
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9575 return 93;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9577 return 94;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9579 return 95;
9580
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9581 return 96;
9582
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9583 return 97;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9585 return 98;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9587 return 99;
9588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9589 return 100;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9591 return 101;
9592
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9593 return 102;
9594
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9595 return 103;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9597 return 104;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9599 return 105;
9600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9601 return 106;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9603 return 107;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9605 return 108;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9607 return 109;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9609 return 110;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9611 return 111;
9612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9613 return 112;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9615 return 113;
9616
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9617 return 114;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9619 return 115;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9621 return 116;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9623 return 117;
9624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9625 return 118;
9626
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9627 return 119;
9628
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9629 return 120;
9630
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9631 return 121;
9632
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9633 return 122;
9634
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9635 return 123;
9636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9637 return 124;
9638
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9639 return 125;
9640
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9641 return 126;
9642
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_state, f))
9643 return 127;
9644
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_state, f))
9645 return 128;
9646
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_ex_state, f))
9647 return 129;
9648
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_ex_state, f))
9649 return 130;
9650
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatemap, f))
9651 return 131;
9652
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatescreen, f))
9653 return 132;
9654 460 return 0;
9655 460 }
9656 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9657 {
9658 //Check what needs writing
9659 258906 word combo_has_flags = 0;
9660
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9661 {
9662
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9663
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9664 {
9665 3190 combo_has_flags |= CHAS_ATTRIB;
9666 3190 break;
9667 }
9668 2052960 }
9669
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9670 460 combo_has_flags |= CHAS_TRIG;
9671
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9672 298 combo_has_flags |= CHAS_FLAG;
9673
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9674
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9675
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9676 28174 combo_has_flags |= CHAS_ANIM;
9677
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9678 6 combo_has_flags |= CHAS_SCRIPT;
9679
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9680 {
9681
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9682 {
9683 combo_has_flags |= CHAS_SCRIPT;
9684 break;
9685 }
9686 2071200 }
9687
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9688
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9689 82514 combo_has_flags |= CHAS_BASIC;
9690
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9691
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9692
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9693
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9694
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9695
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9696
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9697 10 combo_has_flags |= CHAS_LIFT;
9698
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9699
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9700
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9701
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9702
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9703
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9704 258906 combo_has_flags |= CHAS_GENERAL;
9705
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9706 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9707
9708
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9709 {
9710 return 50;
9711 }
9712
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9713 //Write the combo
9714
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9715 {
9716
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9717 return 6;
9718
9719
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9720 return 7;
9721
9722
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9723 return 8;
9724
9725
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9726 return 9;
9727
9728
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9729 return 15;
9730
9731
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9732 return 10;
9733 82514 }
9734
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9735 {
9736 6 p_putcstr(tmp_cmb.label, f);
9737
9738
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9739 return 26;
9740
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9741
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9742 return 27;
9743 6 }
9744
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9745 {
9746
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9747 return 11;
9748
9749
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9750 return 12;
9751
9752
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9753 return 13;
9754
9755
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9756 return 14;
9757
9758
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9759 return 16;
9760
9761
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9762 return 18;
9763
9764
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9765 return 19;
9766 28174 }
9767
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9768 {
9769
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9770
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9771 return 20;
9772
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9773
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9774 return 25;
9775
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9776
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9777 return 32;
9778 3190 }
9779
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9780 {
9781
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9782 return 21;
9783
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9784 return 33;
9785 298 }
9786
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9787 {
9788
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9789
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9790 return 34;
9791
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9792 {
9793 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9794
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9795 460 }
9796
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9797 return 35;
9798 460 }
9799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9800 {
9801
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9802 return 54;
9803
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9804 return 55;
9805
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9806 return 56;
9807
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9808 return 57;
9809
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9810 return 58;
9811
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9812 return 59;
9813
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9814 return 60;
9815
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9816 return 61;
9817
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9818 return 62;
9819
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9820 return 63;
9821
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9822 return 64;
9823
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9824 return 65;
9825
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9826 return 66;
9827
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9828 return 67;
9829
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9830 return 68;
9831
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9832 return 78;
9833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9834 return ret;
9835 258906 }
9836
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9837 {
9838
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9839 return 73;
9840
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9841 return 74;
9842
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9843 return 75;
9844
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9845 return 79;
9846
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9847 return 80;
9848
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9849 return 81;
9850
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9851 return 82;
9852
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9853 return 83;
9854
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9855 return 84;
9856
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9857 return 85;
9858
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9859 return 86;
9860
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9861 return 87;
9862
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9863 return 88;
9864
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9865 return 89;
9866
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9867 return 90;
9868
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9869 return 91;
9870
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9871 return 92;
9872
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9873 return 93;
9874
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9875 return 94;
9876
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9877 return 95;
9878
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9879 return 96;
9880
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9881 return 97;
9882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9883 return 98;
9884 2200 }
9885
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9886 {
9887 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9888 return ret;
9889 }
9890 258906 return 0;
9891 258906 }
9892
9893 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9894 {
9895 //these are here to bypass compiler warnings about unused arguments
9896 9 version=version;
9897 9 build=build;
9898
9899 word combos_used;
9900 9 dword section_id=ID_COMBOS;
9901 9 dword section_version=V_COMBOS;
9902 // dword section_size=0;
9903 9 combos_used = count_combos()-start_combo;
9904
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9905
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9906 9 dword section_size = 0;
9907
9908 //section id
9909
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9910 {
9911 new_return(1);
9912 }
9913
9914 //section version info
9915
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9916 {
9917 new_return(2);
9918 }
9919
9920
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9921 {
9922 new_return(3);
9923 }
9924
9925
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9926 {
9927 18 fake_pack_writing=(writecycle==0);
9928
9929 //section size
9930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9931 {
9932 new_return(4);
9933 }
9934
9935 18 writesize=0;
9936
9937 //finally... section data
9938 18 combos_used=count_combos()-start_combo;
9939
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9941
9942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9943 {
9944 new_return(5);
9945 }
9946
9947 18 size_t end_combo = start_combo+combos_used;
9948
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9949 {
9950 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9951
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9952 258906 }
9953
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9954 {
9955 9 section_size=writesize;
9956 9 }
9957 18 }
9958
9959
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9960 {
9961 displayinfo("Error: writecombos()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9962 }
9963
9964 9 new_return(0);
9965 9 }
9966
9967 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9968 {
9969 //these are here to bypass compiler warnings about unused arguments
9970 9 version=version;
9971 9 build=build;
9972
9973 9 dword section_id=ID_COMBOALIASES;
9974 9 dword section_version=V_COMBOALIASES;
9975 9 dword section_size=0;
9976
9977 //section id
9978
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9979 {
9980 new_return(1);
9981 }
9982
9983 //section version info
9984
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9985 {
9986 new_return(2);
9987 }
9988
9989
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9990 {
9991 new_return(3);
9992 }
9993
9994
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9995 {
9996 18 fake_pack_writing=(writecycle==0);
9997
9998 //section size
9999
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10000 {
10001 new_return(4);
10002 }
10003
10004 18 writesize=0;
10005
10006 //finally... section data
10007
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10008 {
10009
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
10010 {
10011 new_return(5);
10012 }
10013
10014
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
10015 {
10016 new_return(6);
10017 }
10018
10019 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10020
10021
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10022 {
10023 new_return(7);
10024 }
10025
10026
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10027 {
10028 new_return(8);
10029 }
10030
10031
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10032 {
10033 new_return(9);
10034 }
10035
10036
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10037 {
10038
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10039 {
10040 new_return(10);
10041 }
10042 149596 }
10043
10044
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 149596 times.
297052 for(int32_t k=0; k<count; k++)
10045 {
10046
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10047 {
10048 new_return(11);
10049 }
10050 149596 }
10051 147456 }
10052
10053 //Combo pools!
10054 int16_t num_cpools;
10055
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10056 {
10057
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10058 {
10059 2 ++num_cpools;
10060 2 break;
10061 }
10062 147450 }
10063
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10064
10065
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10066 {
10067 new_return(12);
10068 }
10069
10070
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10071 {
10072 6 combo_pool const& pool = combo_pools[cp];
10073 6 int32_t num_combos = pool.combos.size();
10074
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10075 {
10076 new_return(13);
10077 }
10078
10079
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10080 {
10081 26 cpool_entry const& entry = pool.combos.at(q);
10082
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10083 {
10084 new_return(14);
10085 }
10086
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10087 {
10088 new_return(15);
10089 }
10090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if(!p_iputw(entry.quant,f))
10091 {
10092 new_return(16);
10093 }
10094 26 }
10095 6 }
10096
10097 //Autocombos!
10098 int16_t num_cautos;
10099
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10100 {
10101
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10102 {
10103 ++num_cautos;
10104 break;
10105 }
10106 147456 }
10107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10108
10109
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10110 {
10111 new_return(17);
10112 }
10113
10114
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10115 {
10116 combo_auto const& cauto = combo_autos[ca];
10117 if (!p_putc(cauto.getType(), f))
10118 {
10119 new_return(18);
10120 }
10121 if (!p_iputl(cauto.getIconDisplay(), f))
10122 {
10123 new_return(19);
10124 }
10125 if (!p_iputl(cauto.getEraseCombo(), f))
10126 {
10127 new_return(20);
10128 }
10129 if (!p_putc(cauto.getFlags(), f))
10130 {
10131 new_return(21);
10132 }
10133 if (!p_putc(cauto.getArg(), f))
10134 {
10135 new_return(22);
10136 }
10137 int32_t num_combos = cauto.combos.size();
10138 if (!p_iputl(num_combos, f))
10139 {
10140 new_return(23);
10141 }
10142
10143 for (auto q = 0; q < num_combos; ++q)
10144 {
10145 autocombo_entry const& entry = cauto.combos.at(q);
10146 if (!p_putc(entry.ctype, f))
10147 {
10148 new_return(24);
10149 }
10150 if (!p_iputl(entry.cid, f))
10151 {
10152 new_return(25);
10153 }
10154 }
10155 }
10156
10157
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10158 {
10159 9 section_size=writesize;
10160 9 }
10161 18 }
10162
10163
10164
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10165 {
10166 displayinfo("Error: writecomboaliases()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10167 }
10168
10169 9 new_return(0);
10170 }
10171
10172 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10173 {
10174 //these are here to bypass compiler warnings about unused arguments
10175 9 version=version;
10176 9 build=build;
10177 9 start_cset=start_cset;
10178 9 max_csets=max_csets;
10179
10180 9 dword section_id=ID_CSETS;
10181 9 dword section_version=V_CSETS;
10182 9 int32_t palcycles = count_palcycles(&QMisc);
10183 // int32_t palcyccount = count_palcycles(&QMisc);
10184 9 dword section_size = 0;
10185
10186 //section id
10187
10188
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10189 {
10190 new_return(1);
10191 }
10192
10193 //section version info
10194
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10195 {
10196 new_return(2);
10197 }
10198
10199
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10200 {
10201 new_return(3);
10202 }
10203
10204
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10205 {
10206 18 fake_pack_writing=(writecycle==0);
10207
10208 //section size
10209
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10210 {
10211 new_return(4);
10212 }
10213
10214 18 writesize=0;
10215
10216 //finally... section data
10217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10218 {
10219 new_return(5);
10220 }
10221
10222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10223 {
10224 new_return(6);
10225 }
10226
10227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(palcycles,f))
10228 {
10229 new_return(15);
10230 }
10231
10232
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10233 {
10234
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10235 {
10236
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10237 {
10238 new_return(16);
10239 }
10240 1650 }
10241
10242
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10243 {
10244
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10245 {
10246 new_return(17);
10247 }
10248 1650 }
10249
10250
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 1650 times.
2200 for(int32_t j=0; j<3; j++)
10251 {
10252
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10253 {
10254 new_return(18);
10255 }
10256 1650 }
10257 550 }
10258
10259
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10260 {
10261 9 section_size=writesize;
10262 9 }
10263 18 }
10264
10265
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10266 {
10267 displayinfo("Error: writecolordata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10268 }
10269
10270 9 new_return(0);
10271 }
10272
10273 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10274 {
10275 //these are here to bypass compiler warnings about unused arguments
10276 9 version=version;
10277 9 build=build;
10278 9 start_msgstr=start_msgstr;
10279 9 max_msgstrs=max_msgstrs;
10280
10281 9 dword section_id=ID_STRINGS;
10282 9 dword section_version=V_STRINGS;
10283 9 dword section_size = 0;
10284
10285 //section id
10286
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10287 {
10288 new_return(1);
10289 }
10290
10291 //section version info
10292
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10293 {
10294 new_return(2);
10295 }
10296
10297
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10298 {
10299 new_return(3);
10300 }
10301
10302
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10303 {
10304 18 fake_pack_writing=(writecycle==0);
10305
10306 //section size
10307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10308 {
10309 new_return(4);
10310 }
10311
10312 18 writesize=0;
10313
10314 //finally... section data
10315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10316 {
10317 return qe_invalid;
10318 }
10319
10320
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10321 {
10322 836 MsgStrings[i].ensureAsciiEncoding();
10323 836 int32_t sz = MsgStrings[i].s.size();
10324
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10325
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10326 {
10327 return qe_invalid;
10328 }
10329
10330 836 char const* tmpstr = MsgStrings[i].s.c_str();
10331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10332 {
10333
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10334 {
10335 return qe_invalid;
10336 }
10337 836 }
10338
10339
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10340 {
10341 return qe_invalid;
10342 }
10343
10344
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10345 {
10346 return qe_invalid;
10347 }
10348
10349
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10350 {
10351 return qe_invalid;
10352 }
10353
10354
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10355 {
10356 return qe_invalid;
10357 }
10358
10359
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10360 {
10361 return qe_invalid;
10362 }
10363
10364
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10365 {
10366 return qe_invalid;
10367 }
10368
10369
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10370 {
10371 return qe_invalid;
10372 }
10373
10374
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10375 {
10376 return qe_invalid;
10377 }
10378
10379
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10380 {
10381 return qe_invalid;
10382 }
10383
10384
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10385 {
10386 return qe_invalid;
10387 }
10388
10389
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10390 {
10391 return qe_invalid;
10392 }
10393
10394
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10395 {
10396 return qe_invalid;
10397 }
10398
10399
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10400 {
10401
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10402 {
10403 return qe_invalid;
10404 }
10405 3344 }
10406
10407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10408 {
10409 return qe_invalid;
10410 }
10411
10412
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10413 {
10414 return qe_invalid;
10415 }
10416
10417
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10418 {
10419 return qe_invalid;
10420 }
10421
10422
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10423 {
10424 return qe_invalid;
10425 }
10426
10427
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10428 {
10429 return qe_invalid;
10430 }
10431
10432
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10433 {
10434 return qe_invalid;
10435 }
10436
10437
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10438 {
10439 return qe_invalid;
10440 }
10441
10442
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10443 {
10444 return qe_invalid;
10445 }
10446
10447
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10448 {
10449 return qe_invalid;
10450 }
10451
10452
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10453 {
10454 return qe_invalid;
10455 }
10456
10457
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10458 {
10459 return qe_invalid;
10460 }
10461 836 }
10462
10463
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10464 {
10465 9 section_size=writesize;
10466 9 }
10467 18 }
10468
10469
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10470 {
10471 displayinfo("Error: writestrings()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10472 }
10473
10474 9 new_return(0);
10475 9 }
10476
10477 int32_t writestrings_text(PACKFILE *f)
10478 {
10479 std::map<int32_t, int32_t> msglistcache;
10480
10481 for(int32_t index = 1; index<msg_count; index++)
10482 {
10483 for(int32_t i=1; i<msg_count; i++)
10484 {
10485 if(MsgStrings[i].listpos==index)
10486 {
10487 msglistcache[index-1]=i;
10488 break;
10489 }
10490 }
10491 }
10492
10493 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10494 {
10495 fake_pack_writing=(writecycle==0);
10496 char ebuf[32];
10497
10498 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10499
10500 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10501 {
10502 return qe_invalid;
10503 }
10504
10505 for(int32_t i=1; i<msg_count; i++)
10506 {
10507 int32_t str = msglistcache[i-1];
10508
10509 if(!str)
10510 continue;
10511
10512 if(MsgStrings[str].nextstring != 0)
10513 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10514 else
10515 sprintf(ebuf,"\n\n___%d___\n", str);
10516
10517 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10518 {
10519 return qe_invalid;
10520 }
10521
10522 std::string text = MsgStrings[str].serialize();
10523 if (!pfwrite(text.c_str(), text.size(), f))
10524 {
10525 return qe_invalid;
10526 }
10527 }
10528 }
10529
10530 new_return(0);
10531 }
10532
10533 1 int32_t writestrings_tsv(PACKFILE *f)
10534 {
10535 1 std::stringstream ss;
10536
10537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10538
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10539
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10540
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10541
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10542
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10543
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10544
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10545
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10546
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10549
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10550
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10553
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10554
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10555
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10556
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10557
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10558
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10559
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10560
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10561
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10562
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10563 };
10564
10565
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10566 {
10567
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10568
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10569 1 break;
10570
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10571 }
10572
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10573
10574 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10575
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10576
10577
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10578 {
10579 35 auto& msg = MsgStrings[i];
10580
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10581 {
10582
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10583
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10584
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10585 35 break;
10586
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10587
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10588
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10589 35 }
10590
10591
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10592
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10593 {
10594 return qe_invalid;
10595 }
10596
10597 1 new_return(0);
10598 1 }
10599
10600 void parse_strings_tsv(std::string tsv)
10601 {
10602 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10603 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10604 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10605 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10606 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10607 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10608 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10609 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10610 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10611 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10612 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10613 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10614 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10615 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10616 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10617 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10618 { "margin", [&](auto& msg, auto& text){
10619 std::vector<std::string> strs;
10620 util::split(text, strs, ' ');
10621 if (strs.size() != 4)
10622 throw std::runtime_error("margin field must have 4 components");
10623 msg.margins[0] = std::stoi(strs[0]);
10624 msg.margins[1] = std::stoi(strs[1]);
10625 msg.margins[2] = std::stoi(strs[2]);
10626 msg.margins[3] = std::stoi(strs[3]);
10627 } },
10628 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10629 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10630 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10631 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10632 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10633 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10634 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10635 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10636 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10637 };
10638
10639 std::vector<std::string> rows;
10640 util::split(tsv, rows, '\n');
10641 if (rows.size())
10642 {
10643 std::string last = rows.back();
10644 util::trimstr(last);
10645 if (last.empty())
10646 rows.pop_back();
10647 }
10648 if (rows.size() <= 1)
10649 throw std::runtime_error("missing header row");
10650
10651 std::vector<std::string> columns;
10652 util::split(rows[0], columns, '\t');
10653 for (auto name : columns)
10654 {
10655 if (!fields.contains(name))
10656 throw std::runtime_error(fmt::format("invalid field: {}", name));
10657 }
10658
10659 int start_index = 1;
10660 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10661 start_index += 1;
10662
10663 int num_strings = rows.size() - start_index + 1;
10664 if (num_strings > MAXMSGS-1)
10665 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10666
10667 std::vector<MsgStr> msgs;
10668 msgs.reserve(num_strings);
10669 for (int i = start_index; i < rows.size(); i++)
10670 {
10671 std::vector<std::string> strs;
10672 util::split(rows[i], strs, '\t');
10673 if (strs.size() != columns.size())
10674 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10675
10676 int j = 0;
10677 auto& msg = msgs.emplace_back();
10678 for (auto& name : columns)
10679 {
10680 auto& fn = fields[name];
10681 try
10682 {
10683 fn(msg, strs[j++]);
10684 }
10685 catch (std::exception& ex)
10686 {
10687 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10688 }
10689 }
10690 }
10691
10692 init_msgstrings(0, msgs.size());
10693 for (int i = 0; i < msgs.size(); i++)
10694 MsgStrings[i + 1] = msgs[i];
10695 msg_count = msgs.size() + 1;
10696 msglistcache.clear();
10697 }
10698
10699 bool isblanktile(tiledata *buf, int32_t i);
10700 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10701 {
10702 //these are here to bypass compiler warnings about unused arguments
10703 9 version=version;
10704 9 build=build;
10705
10706 int32_t tiles_used;
10707 9 dword section_id=ID_TILES;
10708 9 dword section_version=V_TILES;
10709 9 al_trace("Counting tiles used\n");
10710 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10711
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10712
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10713 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10714 9 dword section_size = 0;
10715
10716 //section id
10717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10718 {
10719 new_return(1);
10720 }
10721
10722 //section version info
10723
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10724 {
10725 new_return(2);
10726 }
10727
10728
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10729 {
10730 new_return(3);
10731 }
10732
10733
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10734 {
10735 18 fake_pack_writing=(writecycle==0);
10736
10737 //section size
10738
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10739 {
10740 new_return(4);
10741 }
10742
10743 18 writesize=0;
10744
10745 //finally... section data
10746 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10747
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10748
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10749
10750
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10751 {
10752 new_return(5);
10753 }
10754
10755
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10756 {
10757
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10758 {
10759
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10760 new_return(8);
10761 365770 }
10762 else
10763 {
10764 330614 int format = newtilebuf[start_tile+i].format;
10765
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10766 {
10767 new_return(6);
10768 }
10769
10770
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10771 {
10772 byte temp_tile[128];
10773 327742 byte *di = temp_tile;
10774 327742 byte *src = newtilebuf[start_tile+i].data;
10775
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10776 {
10777 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10778 41950976 ++di;
10779 41950976 }
10780
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10781 {
10782 new_return(7);
10783 }
10784 327742 }
10785
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10786 {
10787 new_return(7);
10788 }
10789 }
10790 696384 }
10791
10792
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10793 {
10794 9 section_size=writesize;
10795 9 }
10796 18 }
10797
10798
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10799 {
10800 displayinfo("Error: writetiles()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10801 }
10802
10803 9 new_return(0);
10804 }
10805
10806 /* MIDI Format
10807 section_id LONG
10808 section_version WORD
10809 section_cversion WORD
10810 section_size LONG
10811 midi_flags 32 Byte ? BITFIELD[252]
10812
10813 [
10814 title 36
10815 start 4
10816 loop_start 4
10817 loop_end 4
10818 loop 2
10819 volume 2
10820 midi *
10821 ]
10822
10823 */
10824
10825 9 int32_t writemidis(PACKFILE *f)
10826 {
10827 9 dword section_id=ID_MIDIS;
10828 9 dword section_version=V_MIDIS;
10829 9 dword section_size = 0;
10830
10831 //section id
10832
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10833 {
10834 new_return(1);
10835 }
10836
10837 //section version info
10838
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10839 {
10840 new_return(2);
10841 }
10842
10843
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10844 {
10845 new_return(3);
10846 }
10847
10848
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10849 {
10850 18 fake_pack_writing=(writecycle==0);
10851
10852 //section size
10853
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10854 {
10855 new_return(4);
10856 }
10857
10858 18 writesize=0;
10859
10860 //finally... section data
10861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10862 {
10863 new_return(5);
10864 }
10865
10866
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10867 {
10868
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10869 {
10870
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10871 {
10872 new_return(6);
10873 }
10874
10875
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10876 {
10877 new_return(7);
10878 }
10879
10880
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10881 {
10882 new_return(8);
10883 }
10884
10885
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10886 {
10887 new_return(9);
10888 }
10889
10890
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10891 {
10892 new_return(10);
10893 }
10894
10895
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10896 {
10897 new_return(11);
10898 }
10899
10900
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10901 {
10902 new_return(12);
10903 }
10904
10905 130 byte format = MFORMAT_MIDI;
10906
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10907 {
10908 new_return(13);
10909 }
10910
10911
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10912 130 }
10913 4536 }
10914
10915
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10916 {
10917 9 section_size=writesize;
10918 9 }
10919 18 }
10920
10921
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10922 {
10923 displayinfo("Error: writemidis()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10924 }
10925
10926 9 new_return(0);
10927 }
10928
10929 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10930 {
10931 9 dword section_id=ID_CHEATS;
10932 9 dword section_version=V_CHEATS;
10933 9 dword section_size = 0;
10934
10935 //section id
10936
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10937 {
10938 new_return(1);
10939 }
10940
10941 //section version info
10942
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10943 {
10944 new_return(2);
10945 }
10946
10947
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10948 {
10949 new_return(3);
10950 }
10951
10952
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10953 {
10954 18 fake_pack_writing=(writecycle==0);
10955
10956 //section size
10957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10958 {
10959 new_return(4);
10960 }
10961
10962 18 writesize=0;
10963
10964 //finally... section data
10965
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10966 {
10967 new_return(5);
10968 }
10969
10970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10971 {
10972
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10973 {
10974 new_return(6);
10975 }
10976
10977
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10978 {
10979 new_return(7);
10980 }
10981 18 }
10982
10983
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10984 {
10985 9 section_size=writesize;
10986 9 }
10987 18 }
10988
10989
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10990 {
10991 displayinfo("Error: writecheats()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10992 }
10993
10994 9 new_return(0);
10995 }
10996
10997 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10998 {
10999 //these are here to bypass compiler warnings about unused arguments
11000 9 Header=Header;
11001
11002 9 dword section_id=ID_GUYS;
11003 9 dword section_version=V_GUYS;
11004 9 dword section_size=0;
11005
11006 //section id
11007
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11008 {
11009 new_return(1);
11010 }
11011
11012 //section version info
11013
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11014 {
11015 new_return(2);
11016 }
11017
11018
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
11019 {
11020 new_return(3);
11021 }
11022
11023
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11024 {
11025 18 fake_pack_writing=(writecycle==0);
11026
11027 //section size
11028
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11029 {
11030 new_return(4);
11031 }
11032
11033 18 writesize=0;
11034
11035 //finally... section data
11036
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11037 {
11038
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11039 {
11040 new_return(5);
11041 }
11042 9216 }
11043
11044
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11045 {
11046 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11047 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11048
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11049 {
11050 new_return(6);
11051 }
11052
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11053 {
11054 new_return(7);
11055 }
11056
11057
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11058 {
11059 new_return(8);
11060 }
11061
11062
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11063 {
11064 new_return(9);
11065 }
11066
11067
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11068 {
11069 new_return(10);
11070 }
11071
11072
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11073 {
11074 new_return(11);
11075 }
11076
11077
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11078 {
11079 new_return(12);
11080 }
11081
11082
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11083 {
11084 new_return(13);
11085 }
11086
11087
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11088 {
11089 new_return(14);
11090 }
11091
11092
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11093 {
11094 new_return(15);
11095 }
11096
11097
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11098 {
11099 new_return(16);
11100 }
11101
11102
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11103 {
11104 new_return(17);
11105 }
11106
11107
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11108 {
11109 new_return(18);
11110 }
11111
11112
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11113 {
11114 new_return(19);
11115 }
11116
11117
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11118 {
11119 new_return(20);
11120 }
11121
11122
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11123 {
11124 new_return(21);
11125 }
11126
11127
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11128 {
11129 new_return(22);
11130 }
11131
11132
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11133 {
11134 new_return(23);
11135 }
11136
11137
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11138 {
11139 new_return(24);
11140 }
11141
11142
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11143 {
11144 new_return(25);
11145 }
11146
11147
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11148 {
11149 new_return(26);
11150 }
11151
11152
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11153 {
11154 new_return(27);
11155 }
11156
11157
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11158 {
11159 new_return(28);
11160 }
11161
11162
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11163 {
11164 new_return(29);
11165 }
11166
11167
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11168 {
11169 new_return(30);
11170 }
11171
11172
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11173 {
11174 new_return(31);
11175 }
11176
11177
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11178 {
11179 new_return(32);
11180 }
11181
11182
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11183 {
11184 new_return(33);
11185 }
11186
11187
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11188 {
11189 new_return(34);
11190 }
11191
11192
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11193 {
11194 new_return(35);
11195 }
11196
11197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11198 {
11199 new_return(36);
11200 }
11201
11202
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11203 {
11204 new_return(37);
11205 }
11206
11207
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11208 {
11209 new_return(38);
11210 }
11211
11212
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11213 {
11214 new_return(39);
11215 }
11216
11217
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11218 {
11219 new_return(40);
11220 }
11221
11222
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11223 {
11224 new_return(41);
11225 }
11226
11227
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11228 {
11229 new_return(42);
11230 }
11231
11232
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11233 {
11234 new_return(43);
11235 }
11236
11237
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11238 {
11239 new_return(44);
11240 }
11241
11242
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11243 {
11244 new_return(45);
11245 }
11246
11247
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11248 {
11249
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11250 {
11251 new_return(46);
11252 }
11253 175104 }
11254
11255
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11256 {
11257 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11259 //Force SFX_HIT here.
11260
11261 2048 }
11262
11263
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11264 {
11265 new_return(47);
11266 }
11267
11268
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11269 {
11270 new_return(48);
11271 }
11272
11273
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11274 {
11275 new_return(49);
11276 }
11277
11278
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11279 {
11280 new_return(50);
11281 }
11282
11283 //New 2.6 defences
11284
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11285 {
11286
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11287 {
11288 new_return(51);
11289 }
11290 202752 }
11291
11292 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11293
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11294 {
11295 new_return(52);
11296 }
11297
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11298 {
11299 new_return(53);
11300 }
11301
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11302 {
11303 new_return(54);
11304 }
11305
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11306 {
11307 new_return(55);
11308 }
11309
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11310 {
11311 new_return(56);
11312 }
11313 // These are not fixed types, but ints, so they are safe to use here.
11314
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11315 {
11316 new_return(57);
11317 }
11318
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11319 {
11320 new_return(58);
11321 }
11322
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11323 {
11324 new_return(59);
11325 }
11326
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11327 {
11328 new_return(60);
11329 }
11330
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11331 {
11332 new_return(61);
11333 }
11334
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11335 {
11336 new_return(62);
11337 }
11338
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11339 {
11340 new_return(63);
11341 }
11342
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11343 {
11344 new_return(64);
11345 }
11346
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11347 {
11348 new_return(65);
11349 }
11350
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11351 {
11352 new_return(66);
11353 }
11354
11355
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11356 {
11357
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11358 {
11359 new_return(67);
11360 }
11361 92160 }
11362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11363 {
11364 new_return(68);
11365 }
11366 //misc 16->31
11367
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11368 {
11369 new_return(69);
11370 }
11371
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11372 {
11373 new_return(70);
11374 }
11375
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11376 {
11377 new_return(71);
11378 }
11379
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11380 {
11381 new_return(72);
11382 }
11383
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11384 {
11385 new_return(73);
11386 }
11387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11388 {
11389 new_return(74);
11390 }
11391
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11392 {
11393 new_return(75);
11394 }
11395
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11396 {
11397 new_return(76);
11398 }
11399
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11400 {
11401 new_return(77);
11402 }
11403
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11404 {
11405 new_return(78);
11406 }
11407
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11408 {
11409 new_return(79);
11410 }
11411
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11412 {
11413 new_return(80);
11414 }
11415
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11416 {
11417 new_return(81);
11418 }
11419
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11420 {
11421 new_return(82);
11422 }
11423
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11424 {
11425 new_return(83);
11426 }
11427
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11428 {
11429 new_return(84);
11430 }
11431
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11432 {
11433 new_return(85);
11434 }
11435
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11436 {
11437
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11438 {
11439 new_return(86);
11440 }
11441 294912 }
11442
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11443 {
11444
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11445 {
11446 new_return(87);
11447 }
11448 294912 }
11449
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11450 {
11451 new_return(88);
11452 }
11453
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11454 {
11455
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11456 {
11457 new_return(89);
11458 }
11459 73728 }
11460
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11461 {
11462
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11463 {
11464 new_return(90);
11465 }
11466 18432 }
11467
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11468 {
11469 new_return(91);
11470 }
11471 //somehow forgot these in the older builds -Z
11472
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11473 {
11474 new_return(92);
11475 }
11476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11477 {
11478 new_return(93);
11479 }
11480
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11481 {
11482 new_return(94);
11483 }
11484
11485 //Enemy Editor InitD[] labels
11486
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11487 {
11488
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11489 {
11490
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11491 {
11492 new_return(95);
11493 }
11494 4792320 }
11495 73728 }
11496
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11497 new_return(99);
11498
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11499 new_return(100);
11500
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11501 new_return(101);
11502
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11503 new_return(102);
11504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11505 new_return(103);
11506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11507 return ret;
11508 9216 }
11509
11510
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11511 {
11512 9 section_size=writesize;
11513 9 }
11514 18 }
11515
11516
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11517 {
11518 displayinfo("Error: writeguys()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
11519 }
11520
11521 9 new_return(0);
11522 9 }
11523
11524 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11525 {
11526 //these are here to bypass compiler warnings about unused arguments
11527 9 Header=Header;
11528
11529 9 dword section_id=ID_HEROSPRITES;
11530 9 dword section_version=V_HEROSPRITES;
11531 9 dword section_size=0;
11532
11533 //section id
11534
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11535 {
11536 new_return(1);
11537 }
11538
11539 //section version info
11540
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11541 {
11542 new_return(2);
11543 }
11544
11545
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
11546 {
11547 new_return(3);
11548 }
11549
11550
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11551 {
11552 18 fake_pack_writing=(writecycle==0);
11553
11554 //section size
11555
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11556 {
11557 new_return(4);
11558 }
11559
11560 18 writesize=0;
11561
11562 //finally... section data
11563
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11564 {
11565
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11566 {
11567 new_return(5);
11568 }
11569
11570
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11571 {
11572 new_return(5);
11573 }
11574
11575
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11576 {
11577 new_return(5);
11578 }
11579 72 }
11580
11581
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11582 {
11583
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11584 {
11585 new_return(6);
11586 }
11587
11588
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11589 {
11590 new_return(6);
11591 }
11592
11593
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11594 {
11595 new_return(6);
11596 }
11597 72 }
11598
11599
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11600 {
11601
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11602 {
11603 new_return(7);
11604 }
11605
11606
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11607 {
11608 new_return(7);
11609 }
11610
11611
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11612 {
11613 new_return(7);
11614 }
11615 72 }
11616
11617
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11618 {
11619
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11620 {
11621 new_return(8);
11622 }
11623
11624
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11625 {
11626 new_return(8);
11627 }
11628
11629
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11630 {
11631 new_return(8);
11632 }
11633 72 }
11634
11635
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11636 {
11637
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11638 {
11639 new_return(8);
11640 }
11641
11642
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11643 {
11644 new_return(8);
11645 }
11646
11647
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11648 {
11649 new_return(8);
11650 }
11651 72 }
11652
11653
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11654 {
11655
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11656 {
11657 new_return(9);
11658 }
11659
11660
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11661 {
11662 new_return(9);
11663 }
11664
11665
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11666 {
11667 new_return(9);
11668 }
11669 72 }
11670
11671
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11672 {
11673
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11674 {
11675 new_return(10);
11676 }
11677
11678
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11679 {
11680 new_return(10);
11681 }
11682
11683
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11684 {
11685 new_return(10);
11686 }
11687 72 }
11688
11689
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11690 {
11691 new_return(11);
11692 }
11693
11694
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11695 {
11696 new_return(11);
11697 }
11698
11699
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11700 {
11701 new_return(11);
11702 }
11703
11704
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11705 {
11706
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11707 {
11708
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11709 {
11710 new_return(12);
11711 }
11712
11713
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11714 {
11715 new_return(12);
11716 }
11717
11718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11719 {
11720 new_return(12);
11721 }
11722 108 }
11723 36 }
11724
11725
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11726 {
11727
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11728 {
11729 new_return(13);
11730 }
11731
11732
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11733 {
11734 new_return(13);
11735 }
11736
11737
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11738 {
11739 new_return(13);
11740 }
11741 72 }
11742
11743
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11744 {
11745
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11746 {
11747 new_return(13);
11748 }
11749
11750
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11751 {
11752 new_return(13);
11753 }
11754
11755
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11756 {
11757 new_return(13);
11758 }
11759 72 }
11760
11761
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11762 {
11763 new_return(14);
11764 }
11765
11766 //{ V_HEROSPRITES >= 7
11767
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11768 {
11769
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11770 new_return(15);
11771
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11772 new_return(15);
11773
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11774 new_return(15);
11775 72 }
11776
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11777 {
11778
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11779 new_return(15);
11780
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11781 new_return(15);
11782
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11783 new_return(15);
11784 72 }
11785
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11786 {
11787
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11788 new_return(15);
11789
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11790 new_return(15);
11791
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11792 new_return(15);
11793 72 }
11794
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11795 {
11796
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11797 new_return(15);
11798
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11799 new_return(15);
11800
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11801 new_return(15);
11802 72 }
11803
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11804 {
11805
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11806 new_return(15);
11807
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11808 new_return(15);
11809
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11810 new_return(15);
11811 72 }
11812
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11813 {
11814
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11815 new_return(15);
11816
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11817 new_return(15);
11818
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11819 new_return(15);
11820 72 }
11821
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11822 {
11823
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11824 new_return(15);
11825
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11826 new_return(15);
11827
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11828 new_return(15);
11829 72 }
11830
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11831 {
11832
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11833 new_return(15);
11834
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11835 new_return(15);
11836
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11837 new_return(15);
11838 72 }
11839
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11840 {
11841
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11842 new_return(15);
11843
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11844 new_return(15);
11845
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11846 new_return(15);
11847
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11848 new_return(15);
11849 72 }
11850
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11851 {
11852
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11853 new_return(15);
11854
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11855 new_return(15);
11856
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11857 new_return(15);
11858 72 }
11859
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11860 {
11861
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11862 new_return(15);
11863
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11864 new_return(15);
11865
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11866 new_return(15);
11867 72 }
11868
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11869 {
11870
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11871 new_return(15);
11872
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11873 new_return(15);
11874
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11875 new_return(15);
11876 72 }
11877
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11878 {
11879
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11880 new_return(15);
11881
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11882 new_return(15);
11883
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11884 new_return(15);
11885 72 }
11886
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11887 {
11888
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11889 new_return(15);
11890
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11891 new_return(15);
11892
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11893 new_return(15);
11894 72 }
11895
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11896 {
11897
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11898 new_return(15);
11899
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11900 new_return(15);
11901
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11902 new_return(15);
11903 72 }
11904
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11905 {
11906
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11907 new_return(15);
11908
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11909 new_return(15);
11910
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11911 new_return(15);
11912 72 }
11913
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11914 {
11915
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11916 new_return(15);
11917
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11918 new_return(15);
11919
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11920 new_return(15);
11921 72 }
11922
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11923 {
11924
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11925 new_return(15);
11926
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11927 new_return(15);
11928
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11929 new_return(15);
11930 72 }
11931
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11932 {
11933
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11934 new_return(15);
11935
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11936 new_return(15);
11937
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11938 new_return(15);
11939 72 }
11940
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11941 {
11942
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11943 new_return(15);
11944
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11945 new_return(15);
11946
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11947 new_return(15);
11948 72 }
11949
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11950 {
11951
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11952 new_return(15);
11953
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11954 new_return(15);
11955
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11956 new_return(15);
11957 72 }
11958
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11959 {
11960
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11961 new_return(15);
11962
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11963 new_return(15);
11964
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11965 new_return(15);
11966 72 }
11967
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11968 {
11969
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11970 new_return(15);
11971
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11972 new_return(15);
11973
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11974 new_return(15);
11975 72 }
11976
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11977 {
11978
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11979 new_return(15);
11980
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11981 new_return(15);
11982
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11983 new_return(15);
11984 54 }
11985
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11986 {
11987
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11988 new_return(16);
11989
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11990 new_return(16);
11991
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11992 new_return(16);
11993 72 }
11994
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11995 {
11996
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11997 new_return(17);
11998
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11999 new_return(17);
12000
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12001 new_return(17);
12002 72 }
12003
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12004 {
12005
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12006 new_return(17);
12007
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12008 new_return(17);
12009
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12010 new_return(17);
12011 72 }
12012
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12013 {
12014
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12015 new_return(17);
12016
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12017 new_return(17);
12018
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12019 new_return(17);
12020 72 }
12021
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12022 {
12023
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12024 new_return(18);
12025
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12026 new_return(18);
12027
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12028 new_return(18);
12029 72 }
12030
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12031 {
12032
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12033 new_return(19);
12034 72 }
12035
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12036 {
12037
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12038 new_return(20);
12039
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12040 new_return(20);
12041
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12042 new_return(20);
12043 54 }
12044
12045
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12046 {
12047 new_return(21);
12048 }
12049
12050
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12051 {
12052 new_return(21);
12053 }
12054
12055
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12056 {
12057 new_return(21);
12058 }
12059
12060
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12061 {
12062
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12063 new_return(22);
12064
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12065 new_return(22);
12066
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12067 new_return(22);
12068 72 }
12069
12070
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12071 {
12072
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12073 {
12074 new_return(23);
12075 }
12076
12077
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12078 {
12079 new_return(23);
12080 }
12081
12082
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12083 {
12084 new_return(23);
12085 }
12086 72 }
12087
12088
12089
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12090 {
12091
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12092 new_return(15);
12093 2628 }
12094 //}
12095
12096
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12097 {
12098 9 section_size=writesize;
12099 9 }
12100 18 }
12101
12102 //More data will come here
12103
12104
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12105 {
12106 displayinfo("Error: writeherosprites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12107 }
12108
12109 9 new_return(0);
12110 }
12111
12112 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12113 {
12114 9 dword section_id=ID_SUBSCREEN;
12115 9 dword section_version=V_SUBSCREEN;
12116 9 dword section_size=0;
12117
12118 //section id
12119
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12120 {
12121 new_return(1);
12122 }
12123
12124 //section version info
12125
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12126 {
12127 new_return(2);
12128 }
12129
12130
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12131 {
12132 new_return(3);
12133 }
12134
12135
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12136 {
12137 18 fake_pack_writing=(writecycle==0);
12138
12139 //section size
12140
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12141 {
12142 new_return(4);
12143 }
12144
12145 18 writesize=0;
12146
12147 18 byte sz = subscreens_active.size();
12148
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12149 new_return(5);
12150
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12151 {
12152 86 int32_t ret = subscreens_active[i].write(f);
12153 86 fake_pack_writing=(writecycle==0);
12154
12155
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12156 new_return(ret);
12157 86 }
12158
12159 18 sz = subscreens_passive.size();
12160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12161 new_return(5);
12162
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12163 {
12164 64 int32_t ret = subscreens_passive[i].write(f);
12165 64 fake_pack_writing=(writecycle==0);
12166
12167
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12168 new_return(ret);
12169 64 }
12170
12171 18 sz = subscreens_overlay.size();
12172
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12173 new_return(5);
12174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12175 {
12176 int32_t ret = subscreens_overlay[i].write(f);
12177 fake_pack_writing=(writecycle==0);
12178
12179 if(ret!=0)
12180 new_return(ret);
12181 }
12182
12183 18 sz = subscreens_map.size();
12184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12185 new_return(5);
12186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12187 {
12188 int32_t ret = subscreens_map[i].write(f);
12189 fake_pack_writing=(writecycle==0);
12190
12191 if(ret!=0)
12192 new_return(ret);
12193 }
12194
12195
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12196 {
12197 9 section_size=writesize;
12198 9 }
12199 18 }
12200
12201
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12202 {
12203 displayinfo("Error: writesubscreens()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12204 }
12205
12206 9 new_return(0);
12207 9 }
12208
12209 extern script_data *ffscripts[NUMSCRIPTFFC];
12210 extern script_data *itemscripts[NUMSCRIPTITEM];
12211 extern script_data *guyscripts[NUMSCRIPTGUYS];
12212 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12213 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12214 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12215 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12216 extern script_data *playerscripts[NUMSCRIPTHERO];
12217 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12218 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12219 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12220 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12221 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12222
12223 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12224 {
12225
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12226 3 return writeffscript_old(f, Header);
12227
12228 6 dword section_id = ID_FFSCRIPT;
12229 6 dword section_version = V_FFSCRIPT;
12230 6 dword section_size = 0;
12231 6 dword zasmmeta_version = METADATA_V;
12232 6 byte numscripts = 0;
12233 6 numscripts = numscripts; //to avoid unused variables warnings
12234
12235 //section id
12236
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12237 {
12238 new_return(1);
12239 }
12240
12241 //section version info
12242
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12243 {
12244 new_return(2);
12245 }
12246
12247
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12248 {
12249 new_return(3);
12250 }
12251
12252
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12253 {
12254 new_return(4);
12255 }
12256
12257
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12258 {
12259 12 fake_pack_writing=(writecycle==0);
12260
12261 //section size
12262
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12263 {
12264 new_return(5);
12265 }
12266
12267 12 writesize=0;
12268
12269 12 write_quest_zasm(f);
12270
12271
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12272 {
12273 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12274
12275
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12276 {
12277 new_return(ret);
12278 }
12279 6144 }
12280
12281
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12282 {
12283 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12284
12285
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12286 {
12287 new_return(ret);
12288 }
12289 3072 }
12290
12291
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12292 {
12293 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12294
12295
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12296 {
12297 new_return(ret);
12298 }
12299 3072 }
12300
12301
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12302
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12303 {
12304 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12305
12306
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12307 {
12308 new_return(ret);
12309 }
12310 3072 }
12311
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12312
12313
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12314 {
12315 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12316
12317
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12318 {
12319 new_return(ret);
12320 }
12321 3072 }
12322
12323
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12324 {
12325 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12326
12327
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12328 {
12329 new_return(ret);
12330 }
12331 96 }
12332
12333
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12334 {
12335 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12336
12337
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12338 {
12339 new_return(ret);
12340 }
12341 60 }
12342
12343
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12344 {
12345 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12346
12347
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12348 {
12349 new_return(ret);
12350 }
12351 3072 }
12352
12353
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12354 {
12355 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12356
12357
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12358 {
12359 new_return(ret);
12360 }
12361 3072 }
12362
12363
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12364 {
12365 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12366
12367
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12368 {
12369 new_return(ret);
12370 }
12371 3072 }
12372
12373
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12374 {
12375 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12376
12377
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12378 {
12379 new_return(ret);
12380 }
12381 3072 }
12382
12383
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12384 {
12385 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12386
12387
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12388 {
12389 new_return(ret);
12390 }
12391 6144 }
12392
12393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12394 {
12395 new_return(2000);
12396 }
12397
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12398 {
12399 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12400
12401
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12402 {
12403 new_return(ret);
12404 }
12405 6144 }
12406
12407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12408 {
12409 new_return(2001);
12410 }
12411
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12412 {
12413 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12414
12415
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12416 {
12417 new_return(ret);
12418 }
12419 3072 }
12420
12421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12422 {
12423 new_return(2001);
12424 }
12425
12426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12427 {
12428 new_return(2002);
12429 }
12430
12431 12 word numffcbindings=0;
12432
12433
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12434 {
12435
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12436 {
12437 158 numffcbindings++;
12438 158 }
12439 6132 }
12440
12441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12442 {
12443 new_return(2003);
12444 }
12445
12446
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12447 {
12448
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12449 {
12450
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12451 {
12452 new_return(2004);
12453 }
12454
12455
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12456 {
12457 new_return(2005);
12458 }
12459
12460
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12461 {
12462 new_return(2006);
12463 }
12464 158 }
12465 6132 }
12466
12467 12 word numglobalbindings=0;
12468
12469
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12470 {
12471
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12472 {
12473 22 numglobalbindings++;
12474 22 }
12475 96 }
12476
12477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12478 {
12479 new_return(2007);
12480 }
12481
12482
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12483 {
12484
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12485 {
12486
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12487 {
12488 new_return(2008);
12489 }
12490
12491
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12492 {
12493 new_return(2009);
12494 }
12495
12496
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12497 {
12498 new_return(2010);
12499 }
12500 22 }
12501 96 }
12502
12503 12 word numitembindings=0;
12504
12505
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12506 {
12507
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12508 {
12509 26 numitembindings++;
12510 26 }
12511 3060 }
12512
12513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12514 {
12515 new_return(2011);
12516 }
12517
12518
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12519 {
12520
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12521 {
12522
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12523 {
12524 new_return(2012);
12525 }
12526
12527
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12528 {
12529 new_return(2013);
12530 }
12531
12532
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12533 {
12534 new_return(2014);
12535 }
12536 26 }
12537 3060 }
12538
12539 //new script types
12540 //npc scripts
12541 12 word numnpcbindings=0;
12542
12543
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12544 {
12545
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12546 {
12547 numnpcbindings++;
12548 }
12549 3060 }
12550
12551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12552 {
12553 new_return(2015);
12554 }
12555
12556
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12557 {
12558
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12559 {
12560 if(!p_iputw(it->first,f))
12561 {
12562 new_return(2016);
12563 }
12564
12565 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12566 {
12567 new_return(2017);
12568 }
12569
12570 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12571 {
12572 new_return(2018);
12573 }
12574 }
12575 3060 }
12576
12577 //lweapon
12578
12579 12 word numlwpnbindings=0;
12580
12581
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12582 {
12583
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12584 {
12585 2 numlwpnbindings++;
12586 2 }
12587 3060 }
12588
12589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12590 {
12591 new_return(2019);
12592 }
12593
12594
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12595 {
12596
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12597 {
12598
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12599 {
12600 new_return(2020);
12601 }
12602
12603
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12604 {
12605 new_return(2021);
12606 }
12607
12608
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12609 {
12610 new_return(2022);
12611 }
12612 2 }
12613 3060 }
12614
12615 //////
12616
12617 //eweapon
12618
12619
12620 12 word numewpnbindings=0;
12621
12622
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12623 {
12624
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12625 {
12626 numewpnbindings++;
12627 }
12628 3060 }
12629
12630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12631 {
12632 new_return(2023);
12633 }
12634
12635
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12636 {
12637
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12638 {
12639 if(!p_iputw(it->first,f))
12640 {
12641 new_return(2024);
12642 }
12643
12644 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12645 {
12646 new_return(2025);
12647 }
12648
12649 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12650 {
12651 new_return(2026);
12652 }
12653 }
12654 3060 }
12655
12656 //player scripts
12657 12 word numherobindings=0;
12658
12659
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12660 {
12661
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12662 {
12663 numherobindings++;
12664 }
12665 48 }
12666
12667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12668 {
12669 new_return(2027);
12670 }
12671
12672
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12673 {
12674
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12675 {
12676 if(!p_iputw(it->first,f))
12677 {
12678 new_return(2028);
12679 }
12680
12681 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12682 {
12683 new_return(2029);
12684 }
12685
12686 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12687 {
12688 new_return(2030);
12689 }
12690 }
12691 48 }
12692
12693 //dmap scripts
12694 12 word numdmapbindings=0;
12695
12696
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12697 {
12698
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12699 {
12700 10 numdmapbindings++;
12701 10 }
12702 3060 }
12703
12704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12705 {
12706 new_return(2031);
12707 }
12708
12709
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12710 {
12711
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12712 {
12713
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12714 {
12715 new_return(2032);
12716 }
12717
12718
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12719 {
12720 new_return(2033);
12721 }
12722
12723
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12724 {
12725 new_return(2034);
12726 }
12727 10 }
12728 3060 }
12729
12730 //screen scripts
12731 12 word numscreenbindings=0;
12732
12733
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12734 {
12735
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12736 {
12737 4 numscreenbindings++;
12738 4 }
12739 3060 }
12740
12741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12742 {
12743 new_return(2035);
12744 }
12745
12746
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12747 {
12748
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12749 {
12750
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12751 {
12752 new_return(2036);
12753 }
12754
12755
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12756 {
12757 new_return(2037);
12758 }
12759
12760
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12761 {
12762 new_return(2038);
12763 }
12764 4 }
12765 3060 }
12766 //item sprite scripts
12767 12 word numitemspritebindings=0;
12768
12769
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12770 {
12771
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12772 {
12773 numitemspritebindings++;
12774 }
12775 3060 }
12776
12777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12778 {
12779 new_return(2039);
12780 }
12781
12782
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12783 {
12784
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12785 {
12786 if(!p_iputw(it->first,f))
12787 {
12788 new_return(2040);
12789 }
12790
12791 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12792 {
12793 new_return(2041);
12794 }
12795
12796 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12797 {
12798 new_return(2042);
12799 }
12800 }
12801 3060 }
12802
12803 //combo scripts
12804 12 word numcombobindings=0;
12805
12806
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12807 {
12808
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12809 {
12810 numcombobindings++;
12811 }
12812 6132 }
12813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12814 {
12815 new_return(2043);
12816 }
12817
12818
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12819 {
12820
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12821 {
12822 if(!p_iputw(it->first,f))
12823 {
12824 new_return(2044);
12825 }
12826
12827 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12828 {
12829 new_return(2045);
12830 }
12831
12832 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12833 {
12834 new_return(2046);
12835 }
12836 }
12837 6132 }
12838 //subscreen scripts
12839 12 word numgenericbindings=0;
12840
12841
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12842 {
12843
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12844 {
12845 44 numgenericbindings++;
12846 44 }
12847 6132 }
12848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12849 {
12850 new_return(2043);
12851 }
12852
12853
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12854 {
12855
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12856 {
12857
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputw(it->first,f))
12858 {
12859 new_return(2044);
12860 }
12861
12862
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12863 {
12864 new_return(2045);
12865 }
12866
12867
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12868 {
12869 new_return(2046);
12870 }
12871 44 }
12872 6132 }
12873
12874 //generic scripts
12875 12 word numsubscreenbindings=0;
12876
12877
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12878 {
12879
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12880 {
12881 numsubscreenbindings++;
12882 }
12883 3060 }
12884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12885 {
12886 new_return(2047);
12887 }
12888
12889
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12890 {
12891
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12892 {
12893 if(!p_iputw(it->first,f))
12894 {
12895 new_return(2048);
12896 }
12897
12898 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12899 {
12900 new_return(2049);
12901 }
12902
12903 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12904 {
12905 new_return(2050);
12906 }
12907 }
12908 3060 }
12909
12910
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12911 {
12912 6 section_size=writesize;
12913 6 }
12914 12 }
12915
12916
12917
12918
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12919 {
12920 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12921 }
12922
12923 6 new_return(0);
12924 //return 0; //this is just here to stomp the compiler from whining.
12925 //the irony is that it causes an "unreachable code" warning.
12926 9 }
12927
12928 12 int32_t write_quest_zasm(PACKFILE *f)
12929 {
12930 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12931
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12932 {
12933 if(!p_iputl(0,f))
12934 new_return(1);
12935
12936 return 0;
12937 }
12938
12939 12 auto& zasm = zasm_scripts[0]->zasm;
12940 12 size_t num_commands = zasm.size();
12941
12942
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12943 new_return(1);
12944
12945
2/2
✓ Branch 0 taken 373916 times.
✓ Branch 1 taken 12 times.
373928 for(int32_t j=0; j<num_commands; j++)
12946 {
12947 373916 auto& zas = zasm[j];
12948
12949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373916 times.
373916 if(zas.command==0xFFFF)
12950 continue;
12951 else
12952 {
12953
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputw(zas.command,f))
12954 new_return(2);
12955
12956
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputl(zas.arg1,f))
12957 new_return(3);
12958
12959
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputl(zas.arg2,f))
12960 new_return(4);
12961
12962
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputl(zas.arg3,f))
12963 new_return(5);
12964
12965 373916 uint32_t sz = 0;
12966
2/2
✓ Branch 0 taken 372880 times.
✓ Branch 1 taken 1036 times.
373916 if(zas.strptr)
12967 1036 sz = zas.strptr->size();
12968
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputl(sz,f))
12969 new_return(6);
12970
2/2
✓ Branch 0 taken 372894 times.
✓ Branch 1 taken 1022 times.
373916 if(sz)
12971 {
12972 1022 auto& str = *zas.strptr;
12973
2/2
✓ Branch 0 taken 21902 times.
✓ Branch 1 taken 1022 times.
22924 for(size_t q = 0; q < sz; ++q)
12974 {
12975
1/2
✓ Branch 0 taken 21902 times.
✗ Branch 1 not taken.
21902 if(!p_putc(str[q],f))
12976 new_return(7);
12977 21902 }
12978 1022 }
12979 373916 sz = 0;
12980
2/2
✓ Branch 0 taken 373700 times.
✓ Branch 1 taken 216 times.
373916 if(zas.vecptr)
12981 216 sz = zas.vecptr->size();
12982
1/2
✓ Branch 0 taken 373916 times.
✗ Branch 1 not taken.
373916 if(!p_iputl(sz,f))
12983 new_return(8);
12984
2/2
✓ Branch 0 taken 373700 times.
✓ Branch 1 taken 216 times.
373916 if(sz) //vector found
12985 {
12986 216 auto& vec = *zas.vecptr;
12987
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 216 times.
1528 for(size_t q = 0; q < sz; ++q)
12988 {
12989
1/2
✓ Branch 0 taken 1312 times.
✗ Branch 1 not taken.
1312 if(!p_iputl(vec[q],f))
12990 new_return(9);
12991 1312 }
12992 216 }
12993 }
12994 373916 }
12995 12 return 0;
12996 12 }
12997
12998 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12999 {
13000
2/2
✓ Branch 0 taken 45984 times.
✓ Branch 1 taken 252 times.
46236 if (!script->valid())
13001 {
13002
1/2
✓ Branch 0 taken 45984 times.
✗ Branch 1 not taken.
45984 if (!p_putc(0, f))
13003 new_return(-1);
13004 45984 return 0;
13005 }
13006
13007
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if (!p_putc(1, f))
13008 new_return(-1);
13009
13010 252 zasm_meta const& tmeta = script->meta;
13011
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.zasm_v,f))
13012 new_return(1);
13013
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.meta_v,f))
13014 new_return(2);
13015
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.ffscript_v,f))
13016 new_return(3);
13017
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putc((int)tmeta.script_type,f))
13018 new_return(4);
13019
13020
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(int32_t q = 0; q < 8; ++q)
13021 {
13022
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.run_idens[q],f))
13023 new_return(5);
13024 2016 }
13025
13026
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(int32_t q = 0; q < 8; ++q)
13027
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putc(tmeta.run_types[q],f))
13028 new_return(6);
13029
13030
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putc(tmeta.flags,f))
13031 new_return(7);
13032
13033
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v1,f))
13034 new_return(8);
13035
13036
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v2,f))
13037 new_return(9);
13038
13039
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v3,f))
13040 new_return(10);
13041
13042
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v4,f))
13043 new_return(11);
13044
13045
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putcstr(tmeta.script_name,f))
13046 new_return(12);
13047
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putcstr(tmeta.author,f))
13048 new_return(13);
13049
2/2
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 252 times.
2772 for(auto q = 0; q < 10; ++q)
13050 {
13051
1/2
✓ Branch 0 taken 2520 times.
✗ Branch 1 not taken.
2520 if(!p_putcstr(tmeta.attributes[q],f))
13052 new_return(14);
13053
1/2
✓ Branch 0 taken 2520 times.
✗ Branch 1 not taken.
2520 if(!p_putwstr(tmeta.attributes_help[q],f))
13054 new_return(15);
13055 2520 }
13056
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13057 {
13058
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.attribytes[q],f))
13059 new_return(16);
13060
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.attribytes_help[q],f))
13061 new_return(17);
13062 2016 }
13063
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13064 {
13065
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.attrishorts[q],f))
13066 new_return(18);
13067
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13068 new_return(19);
13069 2016 }
13070
2/2
✓ Branch 0 taken 4032 times.
✓ Branch 1 taken 252 times.
4284 for(auto q = 0; q < 16; ++q)
13071 {
13072
1/2
✓ Branch 0 taken 4032 times.
✗ Branch 1 not taken.
4032 if(!p_putcstr(tmeta.usrflags[q],f))
13073 new_return(20);
13074
1/2
✓ Branch 0 taken 4032 times.
✗ Branch 1 not taken.
4032 if(!p_putwstr(tmeta.usrflags_help[q],f))
13075 new_return(21);
13076 4032 }
13077
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13078 {
13079
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.initd[q],f))
13080 new_return(22);
13081
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.initd_help[q],f))
13082 new_return(23);
13083 2016 }
13084
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13085 {
13086
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putc(tmeta.initd_type[q],f))
13087 new_return(24);
13088 2016 }
13089
13090
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputl(script->pc, f))
13091 new_return(25);
13092
13093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!p_iputl(script->end_pc, f))
13094 new_return(26);
13095
13096 252 return 0;
13097 46236 }
13098
13099
13100 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13101 {
13102 3 dword section_id = ID_FFSCRIPT;
13103 3 dword section_version = 26;
13104 3 dword section_cversion = 1;
13105 3 dword section_size = 0;
13106 3 dword zasmmeta_version = 5;
13107 3 byte numscripts = 0;
13108 3 numscripts = numscripts; //to avoid unused variables warnings
13109
13110 //section id
13111
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13112 {
13113 new_return(1);
13114 }
13115
13116 //section version info
13117
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13118 {
13119 new_return(2);
13120 }
13121
13122
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13123 {
13124 new_return(3);
13125 }
13126
13127
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13128 {
13129 new_return(4);
13130 }
13131
13132
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13133 {
13134 6 fake_pack_writing=(writecycle==0);
13135
13136 //section size
13137
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13138 {
13139 new_return(5);
13140 }
13141
13142 6 writesize=0;
13143
13144
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13145 {
13146 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13147 3072 fake_pack_writing=(writecycle==0);
13148
13149
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13150 {
13151 new_return(ret);
13152 }
13153 3072 }
13154
13155
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13156 {
13157 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13158 1536 fake_pack_writing=(writecycle==0);
13159
13160
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13161 {
13162 new_return(ret);
13163 }
13164 1536 }
13165
13166
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13167 {
13168 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13169 1536 fake_pack_writing=(writecycle==0);
13170
13171
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13172 {
13173 new_return(ret);
13174 }
13175 1536 }
13176
13177
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13178
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13179 {
13180 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13181 1536 fake_pack_writing=(writecycle==0);
13182
13183
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13184 {
13185 new_return(ret);
13186 }
13187 1536 }
13188
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13189
13190
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13191 {
13192 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13193 1536 fake_pack_writing=(writecycle==0);
13194
13195
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13196 {
13197 new_return(ret);
13198 }
13199 1536 }
13200
13201
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13202 {
13203 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13204 48 fake_pack_writing=(writecycle==0);
13205
13206
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13207 {
13208 new_return(ret);
13209 }
13210 48 }
13211
13212
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13213 {
13214 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13215 30 fake_pack_writing=(writecycle==0);
13216
13217
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13218 {
13219 new_return(ret);
13220 }
13221 30 }
13222
13223
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13224 {
13225 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13226 1536 fake_pack_writing=(writecycle==0);
13227
13228
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13229 {
13230 new_return(ret);
13231 }
13232 1536 }
13233
13234
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13235 {
13236 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13237 1536 fake_pack_writing=(writecycle==0);
13238
13239
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13240 {
13241 new_return(ret);
13242 }
13243 1536 }
13244
13245
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13246 {
13247 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13248 1536 fake_pack_writing=(writecycle==0);
13249
13250
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13251 {
13252 new_return(ret);
13253 }
13254 1536 }
13255
13256
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13257 {
13258 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13259 1536 fake_pack_writing=(writecycle==0);
13260
13261
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13262 {
13263 new_return(ret);
13264 }
13265 1536 }
13266
13267
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13268 {
13269 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13270 3072 fake_pack_writing=(writecycle==0);
13271
13272
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13273 {
13274 new_return(ret);
13275 }
13276 3072 }
13277
13278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13279 {
13280 new_return(2000);
13281 }
13282
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13283 {
13284 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13285 3072 fake_pack_writing=(writecycle==0);
13286
13287
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13288 {
13289 new_return(ret);
13290 }
13291 3072 }
13292
13293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13294 {
13295 new_return(2001);
13296 }
13297
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13298 {
13299 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13300 1536 fake_pack_writing=(writecycle==0);
13301
13302
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13303 {
13304 new_return(ret);
13305 }
13306 1536 }
13307
13308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13309 {
13310 new_return(2001);
13311 }
13312
13313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13314 {
13315 new_return(2002);
13316 }
13317
13318 6 word numffcbindings=0;
13319
13320
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13321 {
13322
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13323 {
13324 206 numffcbindings++;
13325 206 }
13326 3066 }
13327
13328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13329 {
13330 new_return(2003);
13331 }
13332
13333
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13334 {
13335
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13336 {
13337
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13338 {
13339 new_return(2004);
13340 }
13341
13342
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13343 {
13344 new_return(2005);
13345 }
13346
13347
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13348 {
13349 new_return(2006);
13350 }
13351 206 }
13352 3066 }
13353
13354 6 word numglobalbindings=0;
13355
13356
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13357 {
13358
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13359 {
13360 18 numglobalbindings++;
13361 18 }
13362 48 }
13363
13364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13365 {
13366 new_return(2007);
13367 }
13368
13369
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13370 {
13371
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13372 {
13373
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13374 {
13375 new_return(2008);
13376 }
13377
13378
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13379 {
13380 new_return(2009);
13381 }
13382
13383
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13384 {
13385 new_return(2010);
13386 }
13387 18 }
13388 48 }
13389
13390 6 word numitembindings=0;
13391
13392
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13393 {
13394
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13395 {
13396 18 numitembindings++;
13397 18 }
13398 1530 }
13399
13400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13401 {
13402 new_return(2011);
13403 }
13404
13405
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13406 {
13407
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13408 {
13409
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13410 {
13411 new_return(2012);
13412 }
13413
13414
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13415 {
13416 new_return(2013);
13417 }
13418
13419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13420 {
13421 new_return(2014);
13422 }
13423 18 }
13424 1530 }
13425
13426 //new script types
13427 //npc scripts
13428 6 word numnpcbindings=0;
13429
13430
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13431 {
13432
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13433 {
13434 numnpcbindings++;
13435 }
13436 1530 }
13437
13438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13439 {
13440 new_return(2015);
13441 }
13442
13443
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13444 {
13445
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13446 {
13447 if(!p_iputw(it->first,f))
13448 {
13449 new_return(2016);
13450 }
13451
13452 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13453 {
13454 new_return(2017);
13455 }
13456
13457 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13458 {
13459 new_return(2018);
13460 }
13461 }
13462 1530 }
13463
13464 //lweapon
13465
13466 6 word numlwpnbindings=0;
13467
13468
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13469 {
13470
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13471 {
13472 numlwpnbindings++;
13473 }
13474 1530 }
13475
13476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13477 {
13478 new_return(2019);
13479 }
13480
13481
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13482 {
13483
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13484 {
13485 if(!p_iputw(it->first,f))
13486 {
13487 new_return(2020);
13488 }
13489
13490 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13491 {
13492 new_return(2021);
13493 }
13494
13495 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13496 {
13497 new_return(2022);
13498 }
13499 }
13500 1530 }
13501
13502 //////
13503
13504 //eweapon
13505
13506
13507 6 word numewpnbindings=0;
13508
13509
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13510 {
13511
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13512 {
13513 numewpnbindings++;
13514 }
13515 1530 }
13516
13517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13518 {
13519 new_return(2023);
13520 }
13521
13522
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13523 {
13524
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13525 {
13526 if(!p_iputw(it->first,f))
13527 {
13528 new_return(2024);
13529 }
13530
13531 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13532 {
13533 new_return(2025);
13534 }
13535
13536 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13537 {
13538 new_return(2026);
13539 }
13540 }
13541 1530 }
13542
13543 //player scripts
13544 6 word numherobindings=0;
13545
13546
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13547 {
13548
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13549 {
13550 2 numherobindings++;
13551 2 }
13552 24 }
13553
13554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13555 {
13556 new_return(2027);
13557 }
13558
13559
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13560 {
13561
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13562 {
13563
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13564 {
13565 new_return(2028);
13566 }
13567
13568
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13569 {
13570 new_return(2029);
13571 }
13572
13573
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13574 {
13575 new_return(2030);
13576 }
13577 2 }
13578 24 }
13579
13580 //dmap scripts
13581 6 word numdmapbindings=0;
13582
13583
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13584 {
13585
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13586 {
13587 numdmapbindings++;
13588 }
13589 1530 }
13590
13591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13592 {
13593 new_return(2031);
13594 }
13595
13596
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13597 {
13598
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13599 {
13600 if(!p_iputw(it->first,f))
13601 {
13602 new_return(2032);
13603 }
13604
13605 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13606 {
13607 new_return(2033);
13608 }
13609
13610 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13611 {
13612 new_return(2034);
13613 }
13614 }
13615 1530 }
13616
13617 //screen scripts
13618 6 word numscreenbindings=0;
13619
13620
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13621 {
13622
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13623 {
13624 14 numscreenbindings++;
13625 14 }
13626 1530 }
13627
13628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13629 {
13630 new_return(2035);
13631 }
13632
13633
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13634 {
13635
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13636 {
13637
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13638 {
13639 new_return(2036);
13640 }
13641
13642
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13643 {
13644 new_return(2037);
13645 }
13646
13647
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13648 {
13649 new_return(2038);
13650 }
13651 14 }
13652 1530 }
13653 //item sprite scripts
13654 6 word numitemspritebindings=0;
13655
13656
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13657 {
13658
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13659 {
13660 numitemspritebindings++;
13661 }
13662 1530 }
13663
13664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13665 {
13666 new_return(2039);
13667 }
13668
13669
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13670 {
13671
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13672 {
13673 if(!p_iputw(it->first,f))
13674 {
13675 new_return(2040);
13676 }
13677
13678 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13679 {
13680 new_return(2041);
13681 }
13682
13683 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13684 {
13685 new_return(2042);
13686 }
13687 }
13688 1530 }
13689
13690 //combo scripts
13691 6 word numcombobindings=0;
13692
13693
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13694 {
13695
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13696 {
13697 numcombobindings++;
13698 }
13699 3066 }
13700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13701 {
13702 new_return(2043);
13703 }
13704
13705
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13706 {
13707
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13708 {
13709 if(!p_iputw(it->first,f))
13710 {
13711 new_return(2044);
13712 }
13713
13714 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13715 {
13716 new_return(2045);
13717 }
13718
13719 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13720 {
13721 new_return(2046);
13722 }
13723 }
13724 3066 }
13725 //subscreen scripts
13726 6 word numgenericbindings=0;
13727
13728
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13729 {
13730
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13731 {
13732 numgenericbindings++;
13733 }
13734 3066 }
13735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13736 {
13737 new_return(2043);
13738 }
13739
13740
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13741 {
13742
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13743 {
13744 if(!p_iputw(it->first,f))
13745 {
13746 new_return(2044);
13747 }
13748
13749 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13750 {
13751 new_return(2045);
13752 }
13753
13754 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13755 {
13756 new_return(2046);
13757 }
13758 }
13759 3066 }
13760
13761 //generic scripts
13762 6 word numsubscreenbindings=0;
13763
13764
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13765 {
13766
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13767 {
13768 numsubscreenbindings++;
13769 }
13770 1530 }
13771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13772 {
13773 new_return(2047);
13774 }
13775
13776
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13777 {
13778
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13779 {
13780 if(!p_iputw(it->first,f))
13781 {
13782 new_return(2048);
13783 }
13784
13785 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13786 {
13787 new_return(2049);
13788 }
13789
13790 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13791 {
13792 new_return(2050);
13793 }
13794 }
13795 1530 }
13796
13797
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13798 {
13799 3 section_size=writesize;
13800 3 }
13801 6 }
13802
13803
13804
13805
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13806 {
13807 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
13808 }
13809
13810 3 new_return(0);
13811 //return 0; //this is just here to stomp the compiler from whining.
13812 //the irony is that it causes an "unreachable code" warning.
13813 3 }
13814
13815 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13816 {
13817 //these are here to bypass compiler warnings about unused arguments
13818 23118 Header=Header;
13819 23118 i=i;
13820
13821
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13822
13823
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13824 {
13825 new_return(6);
13826 }
13827
13828 //Metadata
13829 23118 zasm_meta const& tmeta = script->meta;
13830
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13831 {
13832 new_return(7);
13833 }
13834
13835
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13836 {
13837 new_return(8);
13838 }
13839
13840
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13841 {
13842 new_return(9);
13843 }
13844
13845
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13846 {
13847 new_return(10);
13848 }
13849
13850
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13851 {
13852
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13853 new_return(11);
13854 184944 }
13855
13856
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13857 {
13858
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13859 {
13860 new_return(12);
13861 }
13862 184944 }
13863
13864
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13865 {
13866 new_return(13);
13867 }
13868
13869
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13870 {
13871 new_return(14);
13872 }
13873
13874
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13875 {
13876 new_return(15);
13877 }
13878
13879
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13880 {
13881 new_return(16);
13882 }
13883
13884
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13885 {
13886 new_return(17);
13887 }
13888
13889
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13890 new_return(18);
13891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13892 new_return(19);
13893
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13894 {
13895
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13896 new_return(27);
13897
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13898 new_return(28);
13899 231180 }
13900
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13901 {
13902
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13903 new_return(29);
13904
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13905 new_return(30);
13906 184944 }
13907
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13908 {
13909
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13910 new_return(31);
13911
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13912 new_return(32);
13913 184944 }
13914
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13915 {
13916
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13917 new_return(33);
13918
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13919 new_return(34);
13920 369888 }
13921
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13922 {
13923
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13924 new_return(35);
13925
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13926 new_return(36);
13927 184944 }
13928
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13929 {
13930
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13931 new_return(37);
13932 184944 }
13933
13934
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13935 {
13936 2056888 auto& zas = script->zasm_script->zasm[j];
13937
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13938 {
13939 new_return(20);
13940 }
13941
13942
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13943 {
13944 11830 break;
13945 }
13946 else
13947 {
13948
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13949 {
13950 new_return(21);
13951 }
13952
13953
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13954 {
13955 new_return(22);
13956 }
13957
13958
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13959 {
13960 new_return(23);
13961 }
13962
13963 2045058 uint32_t sz = 0;
13964
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13965 2340 sz = zas.strptr->size();
13966
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13967 {
13968 new_return(23);
13969 }
13970
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13971 {
13972 2340 auto& str = *zas.strptr;
13973
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13974 {
13975
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13976 {
13977 new_return(24);
13978 }
13979 214720 }
13980 2340 }
13981 2045058 sz = 0;
13982
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13983 22 sz = zas.vecptr->size();
13984
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13985 {
13986 new_return(25);
13987 }
13988
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13989 {
13990 22 auto& vec = *zas.vecptr;
13991
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13992 {
13993
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13994 {
13995 new_return(26);
13996 }
13997 352 }
13998 22 }
13999 }
14000 2045058 }
14001
14002 23118 new_return(0);
14003 }
14004
14005 extern SAMPLE customsfxdata[WAV_COUNT];
14006 extern uint8_t customsfxflag[WAV_COUNT>>3];
14007
14008 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14009 {
14010 //these are here to bypass compiler warnings about unused arguments
14011 9 Header=Header;
14012
14013 9 dword section_id=ID_SFX;
14014 9 dword section_version=V_SFX;
14015 9 dword section_size=0;
14016
14017 //section id
14018
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14019 {
14020 new_return(1);
14021 }
14022
14023 //section version info
14024
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14025 {
14026 new_return(2);
14027 }
14028
14029
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14030 {
14031 new_return(3);
14032 }
14033
14034
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14035 {
14036 18 fake_pack_writing=(writecycle==0);
14037
14038 //section size
14039
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14040 {
14041 new_return(4);
14042 }
14043
14044 18 writesize=0;
14045
14046
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14047 {
14048
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14049 {
14050 new_return(5);
14051 }
14052 576 }
14053
14054
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14055 {
14056
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14057 3330 continue;
14058
14059
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14060 {
14061 new_return(5);
14062 }
14063 1260 }
14064
14065
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14066 {
14067
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14068 3330 continue;
14069
14070
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14071 {
14072 new_return(5);
14073 }
14074
14075
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14076 {
14077 new_return(6);
14078 }
14079
14080
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14081 {
14082 new_return(7);
14083 }
14084
14085
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14086 {
14087 new_return(8);
14088 }
14089
14090
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14091 {
14092 new_return(9);
14093 }
14094
14095
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14096 {
14097 new_return(10);
14098 }
14099
14100
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14101 {
14102 new_return(11);
14103 }
14104
14105
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14106 {
14107 new_return(12);
14108 }
14109
14110 //de-endianfy the data
14111 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14112
14113
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 28596352 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14114 {
14115
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14116 {
14117 new_return(13);
14118 }
14119 28596352 }
14120 1260 }
14121
14122
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14123 {
14124 9 section_size=writesize;
14125 9 }
14126 18 }
14127
14128
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14129 {
14130 displayinfo("Error: writesfx()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14131 }
14132
14133 9 new_return(0);
14134 }
14135
14136 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14137 {
14138 9 dword section_id=ID_INITDATA;
14139 9 dword section_version=V_INITDATA;
14140 9 dword section_size = 0;
14141
14142 9 zinit.last_map=Map.getCurrMap();
14143 9 zinit.last_screen=Map.getCurrScr();
14144 9 zinit.normalize();
14145
14146 //section id
14147
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14148 {
14149 new_return(1);
14150 }
14151
14152 //section version info
14153
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14154 {
14155 new_return(2);
14156 }
14157
14158
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14159 {
14160 new_return(3);
14161 }
14162
14163 //TODO
14164
14165
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14166 {
14167 18 fake_pack_writing=(writecycle==0);
14168
14169 //section size
14170
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14171 new_return(4);
14172
14173 18 writesize=0;
14174
14175
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14176
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14177 new_return(5);
14178
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14179 {
14180
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14181 new_return(6);
14182 9216 }
14183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14184 new_return(10);
14185
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14186 new_return(11);
14187
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14188
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14189 new_return(12);
14190
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14191
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14192 new_return(13);
14193
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14194 new_return(14);
14195
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14196 new_return(15);
14197
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14198 new_return(16);
14199
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14200 new_return(17);
14201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14202 new_return(18);
14203
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14204 new_return(19);
14205
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14206 new_return(20);
14207
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14208 new_return(21);
14209
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14210 new_return(22);
14211
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14212 new_return(23);
14213
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14214 new_return(24);
14215
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14216 new_return(25);
14217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14218 new_return(26);
14219
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14220 new_return(27);
14221
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14222 new_return(28);
14223
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14224 new_return(29);
14225
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14226 new_return(30);
14227
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14228 new_return(31);
14229
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14230 new_return(32);
14231
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14232 new_return(33);
14233
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14234 new_return(34);
14235
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14236 new_return(35);
14237
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14238 new_return(36);
14239
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14240 new_return(37);
14241
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14242 new_return(38);
14243
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14244 new_return(39);
14245
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14246 new_return(40);
14247
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14248 new_return(41);
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14250 new_return(42);
14251
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14252 new_return(43);
14253
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14254 new_return(44);
14255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14256 new_return(45);
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14258 new_return(46);
14259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14260 new_return(47);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14262 new_return(48);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14264 new_return(49);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14266 new_return(50);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14268 new_return(51);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14270 new_return(52);
14271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14272 new_return(53);
14273
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14274 new_return(54);
14275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14276 new_return(55);
14277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14278 new_return(56);
14279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14280 new_return(57);
14281
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14282 new_return(58);
14283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14284 new_return(59);
14285
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14286 new_return(60);
14287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14288 new_return(61);
14289
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14290 new_return(62);
14291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14292 new_return(63);
14293
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14294 new_return(64);
14295
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14296 new_return(65);
14297
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14298 new_return(66);
14299
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14300 new_return(67);
14301
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14302 new_return(68);
14303
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14304 new_return(69);
14305
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14306 new_return(70);
14307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14308 new_return(71);
14309
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14310 new_return(72);
14311
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14312 new_return(73);
14313
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14314 new_return(74);
14315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14316 new_return(75);
14317
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14318
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14319 new_return(76);
14320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14321 new_return(77);
14322
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14323 new_return(78);
14324
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14325 new_return(79);
14326
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14327 new_return(80);
14328
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14329 new_return(81);
14330
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14331
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14332 new_return(82);
14333
14334
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14335 {
14336 9 section_size=writesize;
14337 9 }
14338 18 }
14339
14340
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14341 {
14342 displayinfo("Error: writeinitdata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14343 }
14344
14345 9 new_return(0);
14346 }
14347
14348 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14349 {
14350 //these are here to bypass compiler warnings about unused arguments
14351 9 Header=Header;
14352
14353 9 dword section_id=ID_ITEMDROPSETS;
14354 9 dword section_version=V_ITEMDROPSETS;
14355 // dword section_size=0;
14356 9 dword section_size = 0;
14357 9 word num_item_drop_sets=count_item_drop_sets();
14358
14359 //section id
14360
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14361 {
14362 new_return(1);
14363 }
14364
14365 //section version info
14366
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14367 {
14368 new_return(2);
14369 }
14370
14371
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14372 {
14373 new_return(3);
14374 }
14375
14376
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14377 {
14378 18 fake_pack_writing=(writecycle==0);
14379
14380 //section size
14381
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14382 {
14383 new_return(4);
14384 }
14385
14386 18 writesize=0;
14387
14388 //finally... section data
14389
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14390 {
14391 new_return(5);
14392 }
14393
14394
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14395 {
14396
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14397 {
14398 new_return(6);
14399 }
14400
14401
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14402 {
14403
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14404 {
14405 new_return(7);
14406 }
14407 2360 }
14408
14409
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 2596 times.
2832 for(int32_t j=0; j<11; ++j)
14410 {
14411
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14412 {
14413 new_return(8);
14414 }
14415 2596 }
14416 236 }
14417
14418
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14419 {
14420 9 section_size=writesize;
14421 9 }
14422 18 }
14423
14424
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14425 {
14426 displayinfo("Error: writeitemdropsets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14427 }
14428
14429 9 new_return(0);
14430 }
14431
14432 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14433 {
14434 9 dword section_id=ID_FAVORITES;
14435 9 dword section_version=V_FAVORITES;
14436 9 dword section_size = 0;
14437
14438 //section id
14439
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14440 {
14441 new_return(1);
14442 }
14443
14444 //section version info
14445
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14446 {
14447 new_return(2);
14448 }
14449
14450
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14451 {
14452 new_return(3);
14453 }
14454
14455
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14456 {
14457 18 fake_pack_writing=(writecycle==0);
14458
14459 //section size
14460
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14461 new_return(4);
14462
14463 18 writesize=0;
14464
14465
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14466 new_return(16);
14467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14468 new_return(17);
14469
14470 18 word favcmb_cnt = 0;
14471
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14472
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14473 {
14474 14 favcmb_cnt = q+1;
14475 14 break;
14476 }
14477
14478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14479 new_return(5);
14480
14481
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14482 {
14483
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14484 new_return(6);
14485
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14486 new_return(7);
14487 460 }
14488
14489
14490 18 word max_combo_cols = MAX_COMBO_COLS;
14491
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14492 new_return(9);
14493
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14494 {
14495
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14496 new_return(10);
14497
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14498 new_return(11);
14499
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14500 new_return(12);
14501 72 }
14502 18 word max_mappages = MAX_MAPPAGE_BTNS;
14503
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14504 new_return(13);
14505
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14506 {
14507
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14508 new_return(14);
14509
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14510 new_return(15);
14511 162 }
14512
14513
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14514 {
14515 9 section_size=writesize;
14516 9 }
14517 18 }
14518
14519
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14520 {
14521 displayinfo("Error: writefavorites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14522 }
14523
14524 9 new_return(0);
14525 }
14526
14527 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14528 {
14529
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14530 9 reset_combo_animations();
14531 9 reset_combo_animations2();
14532 9 strcpy(header.id_str,QH_NEWIDSTR);
14533 9 header.zelda_version = ZELDA_VERSION;
14534 9 header.internal = INTERNAL_VERSION;
14535 9 header.data_flags[ZQ_TILES] = true;
14536 9 header.data_flags[ZQ_CHEATS2] = 1;
14537 9 header.build=VERSION_BUILD;
14538
14539
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14540 {
14541 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14542 2268 }
14543
14544 char zinfofilename[2048];
14545 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14546
14547 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14548 9 box_out("Saving Quest...");
14549 9 box_eol();
14550 9 box_eol();
14551
14552
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14554
14555
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14556 return 1;
14557
14558
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14559
14560
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14561 return 2;
14562
14563
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14564
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14565
14566
14567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14568 {
14569 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14570
14571 box_out("Writing ZInfo...");
14572 if(inf)
14573 {
14574 if(writezinfo(inf,ZI)!=0)
14575 return 2;
14576
14577 pack_fclose(inf);
14578 box_out("okay.");
14579 }
14580 else box_out(" ...file failure");
14581 box_eol();
14582 }
14583 else
14584 {
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14586
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14587 return 2;
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14589
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14590 }
14591
14592
14593
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14594
14595
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14596 return 3;
14597
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14599
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14600
14601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14602
14603
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14604 return 4;
14605
14606
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14607
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14608
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14610
14611
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14612 return 5;
14613
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14615
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14616
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14618
14619
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14620 return 6;
14621
14622
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14623
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14624
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14626
14627
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14628 return 7;
14629
14630
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14631
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14632
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14634
14635
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14636 return 8;
14637
14638
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14639
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14640
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14642
14643
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14644 return 9;
14645
14646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14647
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14650
14651
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14652 return 10;
14653
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14655
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14658
14659
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14660 return 11;
14661
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14663
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14666
14667
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14668 return 12;
14669
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14674
14675
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14676 return 13;
14677
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14679
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14682
14683
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14684 return 14;
14685
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14687
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14690
14691
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14692 return 15;
14693
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14695
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14698
14699
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14700 return 16;
14701
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14703
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14706
14707
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14708 return 17;
14709
14710
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14711
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14712
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14714
14715
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14716 return 18;
14717
14718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14719
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14720
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14722
14723
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14724 return 19;
14725
14726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14727
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14728
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14730
14731
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14732 return 20;
14733
14734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14735
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14736
14737
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14738
14739
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14740 return 21;
14741
14742
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14743
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14744
14745
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14746
14747
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14748 return 22;
14749
14750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14751
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14752
14753
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14754
14755
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14756 return 23;
14757
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14759
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14760
14761
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14762
14763
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14764 return 24;
14765
14766
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14767
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14768
14769
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14770
14771
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14772 return 25;
14773
14774
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14776
14777
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14778
14779
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14780 return 26;
14781
14782
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14783
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14784
14785
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14786
14787
14788
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14789 {
14790 char const* kfname = filename;
14791 char keyfilename[2048]={0};
14792 zprint2("Writing key files for '%s'\n", kfname);
14793
14794 char temp_pw[QSTPWD_LEN] = {0};
14795 uint ind = 0;
14796 for(char const* ext : {"key","zpwd","zcheat"})
14797 {
14798 replace_extension(keyfilename, kfname, ext, 2047);
14799 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14800 char msg[80] = {0};
14801 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14802 msg[78]=13;
14803 msg[79]=10;
14804 pfwrite(msg, 80, fp);
14805 p_iputw(header.zelda_version,fp);
14806 p_putc(header.build,fp);
14807 char const* pwd = header.password;
14808 if(ind == 2) //.zcheat, hashed pwd
14809 {
14810 char hashmap = 'Z';
14811 hashmap += 'Q';
14812 hashmap += 'U';
14813 hashmap += 'E';
14814 hashmap += 'S';
14815 hashmap += 'T';
14816 for ( int q = 0; q < QSTPWD_LEN; ++q )
14817 {
14818 temp_pw[q] = header.password[q];
14819 temp_pw[q] += hashmap;
14820 }
14821 pwd = temp_pw;
14822 }
14823 pfwrite(pwd, strlen(pwd), fp);
14824 pack_fclose(fp);
14825 ++ind;
14826 }
14827 }
14828
14829 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14830 9 std::error_code ec;
14831
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14833 {
14834 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14835 return ec.value();
14836 }
14837
14838
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14839
14840 #ifdef __EMSCRIPTEN__
14841 em_sync_fs();
14842 #endif
14843
14844 9 return 0;
14845 9 }
14846
14847 // #ifdef _WIN32
14848 // static std::time_t to_time_t(FILETIME const& ft) {
14849 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14850 // t -= 116444736000000000ull;
14851 // t /= 10000000u;
14852 // return static_cast<std::time_t>(t);
14853 // }
14854 // #else
14855 // #endif
14856 template<typename TP>
14857 5 static std::time_t to_time_t(TP tp) {
14858 using namespace std::chrono;
14859 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14860 5 return system_clock::to_time_t(sctp);
14861 }
14862
14863 5 std::string get_time_last_modified_string(std::string path)
14864 {
14865
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14866 // TODO: C++20 but not supported yet.
14867 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14868 5 std::time_t tt = to_time_t(write_time);
14869 5 std::tm *gmt = std::gmtime(&tt);
14870 5 std::stringstream buffer;
14871
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14872
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14873 5 return formattedFileTime;
14874
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14875
14876 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14877 {
14878 // Always backup quest if it was last saved in a different version of the editor,
14879 // or if this a new file and is overwritting another qst file.
14880
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14881 {
14882 5 std::string backup_name;
14883
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14884
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14885 {
14886
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14887 5 }
14888 else
14889 {
14890 backup_name = fmt::format("{}", last_mod);
14891 }
14892
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14893
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14894
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14895 {
14896
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14897
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14898 {
14899
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14900 5 }
14901 else
14902 {
14903 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14904 }
14905 5 }
14906 5 }
14907
14908 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14909 9 fake_pack_writing = false;
14910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14911 {
14912 box_out("-- Error saving quest file! --");
14913 box_end(true);
14914 }
14915 9 else box_end(false);
14916 9 return ret;
14917 }
14918
14919 9 int32_t save_quest(const char *filename, bool timed_save)
14920 {
14921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14922
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14923 char ext1[5];
14924 9 ext1[0]=0;
14925
14926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14927 {
14928 sprintf(ext1, "qt");
14929 }
14930 else
14931 {
14932 9 sprintf(ext1, "qb");
14933 }
14934
14935
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14936 {
14937 char backupname[2048];
14938 char backupname2[2048];
14939 char ext[12];
14940
14941 for(int32_t i=retention-1; i>0; --i)
14942 {
14943 sprintf(ext, "%s%d", ext1, i-1);
14944 replace_extension(backupname, filepath, ext, 2047);
14945
14946 if(exists(backupname))
14947 {
14948 sprintf(ext, "%s%d", ext1, i);
14949 replace_extension(backupname2, filepath, ext, 2047);
14950
14951 if(exists(backupname2))
14952 {
14953 remove(backupname2);
14954 }
14955
14956 rename(backupname, backupname2);
14957 }
14958 }
14959
14960 //don't do this if we're not saving to the same name -DD
14961 if(!timed_save && !strcmp(filepath, filename))
14962 {
14963 sprintf(ext, "%s%d", ext1, 0);
14964 replace_extension(backupname, filepath, ext, 2047);
14965 rename(filepath, backupname);
14966 }
14967 }
14968
14969 int32_t ret;
14970 9 ret = save_unencoded_quest(filename, compress, filename);
14971
14972 9 return ret;
14973 }
14974
14975 1 void center_zq_class_dialogs()
14976 {
14977 1 jwin_center_dialog(pwd_dlg);
14978 1 }
14979
14980 void zmap::prv_secrets(bool high16only)
14981 {
14982 mapscr *s = &prvscr;
14983 mapscr *t = prvlayers;
14984 int32_t ft=0;
14985
14986 for(int32_t i=0; i<176; i++)
14987 {
14988 if(!high16only)
14989 {
14990 for(int32_t j=-1; j<6; j++)
14991 {
14992 int32_t newflag = -1;
14993
14994 for(int32_t iter=0; iter<2; ++iter)
14995 {
14996 if(!t[j].valid)
14997 continue;
14998
14999 int32_t checkflag=combobuf[t[j].data[i]].flag;
15000
15001 if(iter==1)
15002 {
15003 checkflag=t[j].sflag[i];
15004 }
15005
15006 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15007 if (ft != -1)
15008 {
15009 if(j==-1)
15010 {
15011 s->data[i] = s->secretcombo[ft];
15012 s->cset[i] = s->secretcset[ft];
15013 newflag = s->secretflag[ft];
15014 }
15015 else
15016 {
15017 t[j].data[i] = t[j].secretcombo[ft];
15018 t[j].cset[i] = t[j].secretcset[ft];
15019 newflag = t[j].secretflag[ft];
15020 }
15021 }
15022 }
15023
15024 if(newflag >-1)
15025 {
15026 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15027 }
15028 }
15029 }
15030
15031 //if(true)
15032 //{
15033 int32_t newflag = -1;
15034
15035 for(int32_t iter=0; iter<2; ++iter)
15036 {
15037 int32_t checkflag=combobuf[s->data[i]].flag;
15038
15039 if(iter==1)
15040 {
15041 checkflag=s->sflag[i];
15042 }
15043
15044 if((checkflag > 15)&&(checkflag < 32))
15045 {
15046 s->data[i] = s->secretcombo[(checkflag)-16+4];
15047 s->cset[i] = s->secretcset[(checkflag)-16+4];
15048 newflag = s->secretflag[(checkflag)-16+4];
15049 // putit = true;
15050 }
15051 }
15052
15053 if(newflag >-1) s->sflag[i] = newflag;
15054
15055 for(int32_t j=0; j<6; j++)
15056 {
15057 if(!t[j].valid) continue;
15058
15059 int32_t newflag2 = -1;
15060
15061 for(int32_t iter=0; iter<2; ++iter)
15062 {
15063 int32_t checkflag=combobuf[t[j].data[i]].flag;
15064
15065 if(iter==1)
15066 {
15067 checkflag=t[j].sflag[i];
15068 }
15069
15070 if((checkflag > 15)&&(checkflag < 32))
15071 {
15072 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15073 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15074 newflag2 = t[j].secretflag[(checkflag)-16+4];
15075 }
15076 }
15077
15078 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15079 }
15080 }
15081
15082 //FFCs
15083 word num_ffcs = s->numFFC();
15084 for(word i=0; i<num_ffcs; ++i)
15085 {
15086 if(!high16only)
15087 {
15088 for(int32_t iter=0; iter<1; ++iter)
15089 {
15090 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15091
15092 if(iter==1)
15093 {
15094 checkflag=s->sflag[i];
15095 }
15096
15097 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15098 if (ft != -1)
15099 {
15100 s->ffcs[i].data = s->secretcombo[ft];
15101 s->ffcs[i].cset = s->secretcset[ft];
15102 }
15103 }
15104 }
15105
15106 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15107 {
15108 for(int32_t iter=0; iter<1; ++iter)
15109 {
15110 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15111
15112 if(iter==1)
15113 {
15114 // FFCs can't have flags! Yet...
15115 }
15116
15117 if((checkflag > 15)&&(checkflag < 32))
15118 {
15119 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15120 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15121 }
15122 }
15123 }
15124 }
15125 }
15126